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