Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- using namespace std;
- int x[100], n, nrsol=0, 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 estevalid(int k){
- return true;
- }
- int solutie(int k){
- return k==n;
- }
- void tipar(){
- nrsol++;
- cout<<"\nParitia "<<nrsol<<":"<<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;
- }
- }
- void back(){
- int k=1;
- init(1);
- while(k>0)
- {
- while (existasuccesor(k))
- {
- x[k]=x[k]+1;
- if (estevalid(k))
- if (solutie(k)) tipar();
- else
- {
- k++;
- init(k);
- }
- }
- k--;
- }
- }
- int main(){
- cout<<"cate elemente sunt? "; cin>>n;
- back();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement