SHARE
TWEET

asgf

a guest Nov 17th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int m,p,q,nr0,nr1,nr2,k,n,x[100];
  4. int cond (int k)
  5. {
  6.     nr0=0;
  7.     nr1=0;
  8.     nr2=0;
  9.     for(int i=1;i<=n;i++)
  10.         if(x[i]==0) nr0++;
  11.         else if(x[i]==1) nr1++;
  12.         else if(x[i]==2) nr2++;
  13.     if(nr0==m && nr1==p && nr2==q) return 1;
  14.     else return 0;
  15. }
  16. int solutie (int k)
  17. {
  18.     return (k==n);
  19. }
  20. void afisare()
  21. {
  22.     for(int i=1;i<=k;i++)
  23.         cout<<x[i]<<" ";
  24.     cout<<endl;
  25. }
  26. void back()
  27. {
  28.     int gasit;
  29.     k=1;
  30.     x[k]=-1;
  31.     while(k>0)
  32.     {
  33.         gasit==0;
  34.         while(x[k]<2 && gasit==0)
  35.         {
  36.             x[k]++;
  37.             if(cond(k)==1) gasit=1;
  38.         }
  39.         if(gasit==1) if(solutie(k)==1) afisare();
  40.                      else {k++;
  41.                            x[k]=0;}
  42.         else k--;
  43.     }
  44. }
  45. int main()
  46. {
  47.     cin>>n>>m>>p>>q;
  48.     back();
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top