Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int st[100], i, k, n, s;
- void init()
- {
- st[k]=0;
- }
- int succesor()
- {
- s=0;
- if(k>1)
- for(i=1;i<k;i++)
- s+=st[i];
- if(st[k]<n-s)
- {
- st[k]++;
- return 1;
- }
- else return 0;
- }
- int valid()
- {
- return 1;
- }
- int solutie()
- {
- s=0;
- for(i=1;i<=k;i++)
- s+=st[i];
- return s==n;
- }
- void tipar()
- {
- for(i=1;i<k;i++)
- cout<<st[i]<<" ";
- cout<<st[k];
- cout<<endl;
- }
- void btr()
- {
- int AS;
- k=1;
- init();
- while(k>0)
- {
- do
- {}while((AS=succesor())&&(!valid()));
- if(AS)
- if(solutie())
- tipar();
- else
- {
- k++;
- init();
- }
- else k--;
- }
- }
- int main()
- {
- cin>>n;
- btr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement