Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sol, n, x[100], Max;
- void init(int k)
- {
- x[k]=0;
- }
- int existaSuccesor(int k)
- {
- Max=0;
- for(int i=1; i<k; i++)
- if(x[i]>Max)
- Max=x[i];
- return x[k]<=Max;
- }
- int cont(int k)
- {
- return 1;
- }
- int solutie(int k)
- {
- return k==n;
- }
- void tipar()
- {
- sol++;
- cout<<"\nPartitia cu numarul "<<sol<<" :"<<endl;
- if(Max<x[n])
- Max=x[n];
- for(int m=1; m<=Max; m++)
- {
- cout<<"Submultimea "<<m<<": ";
- for(int i=1; i<=n; i++)
- if(x[i]==m)
- cout<<i<<" ";
- cout<<endl;
- }
- cout<<endl;
- }
- void back()
- {
- int k=1;
- init(1);
- while(k>0)
- {
- if(existaSuccesor(k))
- {
- x[k]++;
- if(cont(k))
- if(solutie(k))
- tipar();
- else
- {
- k++;
- init(k);
- }
- }
- else
- k--;
- }
- }
- int main()
- {
- cout<<"cate persoane sunt? "; cin>>n;
- cout<<"Submultimile de bisericute sunt: "<<endl;
- back();
- return 0;
- }
Add Comment
Please, Sign In to add comment