Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int w[100000],x[100000],m,n;
- class SumofsubSet{
- public:
- void sum(int s,int k,int r)
- {
- x[k] = 1;
- if(s+w[k] == m)
- {
- display(k);
- }
- else if (s+w[k]+w[k+1]<=m)
- sum(s+w[k],k+1,r-w[k]);
- if((((s+r)-w[k])>=m) &&(s+w[k+1])<=m)
- {
- x[k] = 0;
- sum(s,k+1,r-w[k]);
- }
- }
- void display(int k)
- {
- for(int i=1;i<=k;i++)
- {
- if( x[i] == 1)
- cout<<w[i]<<" ";
- }
- cout<<endl;
- }
- };
- int main()
- {
- ifstream fin("input.txt", ios::in) ;
- //freopen("input.txt","r",stdin);
- SumofsubSet ss;
- fin>>n>>m;
- int total = 0;
- for(int i =1; i<=n;i++)
- {
- fin>>w[i];
- total = total+ w[i];
- }
- // outfile.open("input.txt");
- // outfile.close();
- fin.close();
- int a,b,c;
- cin>>a>>b;
- cout<<a<<b;
- ss.sum(0,1,total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement