fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. #define fi first
  7. #define se second
  8. #define pii pair<int, int>
  9.  
  10.  
  11. const int mod = 1e9 + 7;
  12. const int N = 1e6 + 5;
  13. int x[35], y[35], ans = 0, u, v, mid, n;
  14. map<pii, int> mp;
  15.  
  16.  
  17. void bt1(int i = 1, int tongx = 0, int tongy = 0) {
  18. if (i == mid + 1) {
  19. ++mp[{tongx, tongy}];
  20. return;
  21. }
  22. bt1(i + 1, tongx, tongy);
  23. bt1(i + 1, tongx + x[i], tongy + y[i]);
  24. }
  25. void bt2(int i = mid + 1, int tongx = 0, int tongy = 0) {
  26. // if (tongx > u || tongy > v) return;
  27. if (i == n + 1) {
  28. if (mp.find({u - tongx, v - tongy}) != mp.end()) ans += mp[{u - tongx, v - tongy}];
  29. return;
  30. }
  31. bt2(i + 1, tongx, tongy);
  32. bt2(i + 1, tongx + x[i], tongy + y[i]);
  33. }
  34. void output() {
  35. mid = n / 2;
  36. bt1();
  37. bt2();
  38. cout << ans;
  39. }
  40. void input() {
  41. cin >> n >> u >> v;
  42. for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i];
  43. }
  44. signed main () {
  45. if(fopen("", "r")) {
  46. freopen("", "r", stdin);
  47. freopen("", "w", stdout);
  48. }
  49.  
  50. ios_base::sync_with_stdio(false);
  51. cin.tie(nullptr); cout.tie(nullptr);
  52.  
  53. input();
  54. output();
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
1