Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- long long ans;
- int N,C;
- int arr[35];
- int half;
- map<int,int> mL,mR;
- vector<int> L,R;
- map<int,bool> chk;
- void bfL(int idx, int c)
- {
- if(idx==half)
- {
- if(!mL[c]) L.push_back(c);
- mL[c]++;
- return;
- }
- bfL(idx+1,c);
- bfL(idx+1,c+arr[idx]);
- }
- void bfR(int idx, int c)
- {
- if(idx==N)
- {
- if(!mR[c]) R.push_back(c);
- mR[c]++;
- return;
- }
- bfR(idx+1,c);
- bfR(idx+1,c+arr[idx]);
- }
- int main()
- {
- scanf("%d %d",&N,&C);
- half = N / 2;
- for(int i=0; i<N; i++)
- {
- scanf("%d",arr+i);
- }
- bfL(0,0);
- bfR(half,0);
- sort(L.begin(),L.end());
- sort(R.begin(),R.end());
- for(int i : L)
- {
- auto it = std::lower_bound(R.begin(),R.end(),i);
- ans+=it-R.begin()+1;
- }
- printf("%lld",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement