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);
- }
- if(s+w[k] == m)
- {
- //display(k);
- }
- else if (s+w[k]<=m && k<n)
- sum(s+w[k],k+1,r-w[k]);
- //cout<<k<<" "<<endl;
- if((s+w[k+1])!=m && k<n )
- {
- 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()
- {
- //freopen("input.txt","r",stdin);
- SumofsubSet ss;
- cin>>n>>m;
- int total = 0;
- for(int i =1; i<=n;i++)
- {
- cin>>w[i];
- total = total+ w[i];
- }
- ss.sum(0,1,total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement