Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- ll n,w,product[50];
- vector<ll>v1,v2;
- void sol1(ll x,ll y,ll sum)
- {
- if(sum>w)
- return;
- if(x==y && sum<=w)
- {
- v1.push_back(sum);
- return;
- }
- sol1(x+1,y,product[x]+sum);
- sol1(x+1,y,sum);
- }
- void sol2(ll x,ll y,ll sum)
- {
- if(sum>w)
- return;
- if(x==y && sum<=w)
- {
- v2.push_back(sum);
- return;
- }
- sol2(x+1,y,product[x]+sum);
- sol2(x+1,y,sum);
- }
- int main()
- {
- ll t,i,j,cas;
- cin>>t;
- for(cas=1;cas<=t;cas++)
- {
- cin>>n>>w;
- for(i=0;i<n;i++)
- cin>>product[i];
- v1.clear();
- v2.clear();
- sol1(0,n/2,0);
- sol2(n/2,n,0);
- sort(v1.begin(),v1.end());
- sort(v2.begin(),v2.end());
- ll res=0;
- for(i=0;i<v1.size();i++)
- {
- if(w-v1[i]>=0)
- res+=(upper_bound(v2.begin(),v2.end(),w-v1[i])-v2.begin());
- }
- cout<<"Case "<<cas<<": "<<res<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement