Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <map>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. long long ans;
  9. int N,C;
  10. int arr[35];
  11. int half;
  12.  
  13. map<int,int> mL,mR;
  14. vector<int> L,R;
  15. map<int,bool> chk;
  16.  
  17. void bfL(int idx, int c)
  18. {
  19. if(idx==half)
  20. {
  21. if(!mL[c]) L.push_back(c);
  22. mL[c]++;
  23. return;
  24. }
  25.  
  26. bfL(idx+1,c);
  27. bfL(idx+1,c+arr[idx]);
  28. }
  29.  
  30. void bfR(int idx, int c)
  31. {
  32. if(idx==N)
  33. {
  34. if(!mR[c]) R.push_back(c);
  35. mR[c]++;
  36. return;
  37. }
  38.  
  39. bfR(idx+1,c);
  40. bfR(idx+1,c+arr[idx]);
  41. }
  42.  
  43. int main()
  44. {
  45. scanf("%d %d",&N,&C);
  46. half = N / 2;
  47. for(int i=0; i<N; i++)
  48. {
  49. scanf("%d",arr+i);
  50. }
  51.  
  52. bfL(0,0);
  53. bfR(half,0);
  54.  
  55. sort(L.begin(),L.end());
  56. sort(R.begin(),R.end());
  57.  
  58. for(int i : L)
  59. {
  60. auto it = std::lower_bound(R.begin(),R.end(),i);
  61. ans+=it-R.begin()+1;
  62. }
  63.  
  64. printf("%lld",ans);
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement