Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int m1,p1,q1,n,m,p,q,k,x[100];
- int cond(int k)
- {if(m1>m||p1>p||q1>q)
- return 0;
- return 1;
- }
- int sol(int k)
- {return(k==n);
- }
- void afisare()
- {
- for(int i=1;i<=k;i++)
- cout<<x[i]<<" ";
- cout<<endl;
- }
- void back()
- {
- k=1;
- x[k]=-1;
- int gasit;
- while(k>0)
- {
- gasit=0;
- while(gasit==0&&x[k]<=2)
- {
- x[k]++;
- if(cond(k)==1)
- {gasit=1;
- if(x[k]==0)
- m1++;
- else if(x[k]==1)
- p1++;
- else q1++;
- }}
- if(gasit==1)
- if(sol(k)==1)
- afisare();
- else{k++;
- x[k]=-1;}
- else {k--;
- if(x[k]==0)
- m1--;
- else if(x[k]==1)
- p1--;
- else q1--;
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement