SHARE
TWEET

Untitled

a guest Oct 10th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. int x[11],a[11],c,b,n;
  7.  
  8.  
  9. bool valid(int k)
  10. {
  11.     int i;
  12.     for(i=1;i<k;i++)
  13.         {if(x[i]==x[k])
  14.         return 0;
  15.         if(x[i]>x[k] and a[x[i]]==a[x[k]])
  16.             return 0;
  17.         }
  18.     return 1;
  19. }
  20.  
  21. void afisare(int k)
  22. {
  23.     int i;
  24.     for(i=1;i<=k;i++)
  25.         cout<<a[x[i]];
  26.     cout<<'\n';
  27.  
  28. }
  29.  
  30. void bkt()
  31. {
  32.   int k=1;
  33.   x[k]=0;
  34.  
  35.   while(k)
  36.   {
  37.       x[k]++;
  38.       if(x[k]<=n)
  39.       {
  40.           if(valid(k))
  41.           {
  42.               if(k==n)
  43.                 afisare(k);
  44.               else
  45.               {
  46.                   k++;
  47.                   x[k]=0;
  48.               }
  49.           }
  50.       }
  51.       else
  52.         k--;
  53.   }
  54.  
  55. }
  56. int main()
  57. {
  58.     int i;
  59.     cin>>n;
  60.  
  61.  
  62.   while(n)
  63.   {
  64.       if(n%2!=0)
  65.         c++;
  66.       else
  67.         b++;
  68.       n=n/2;
  69.   }
  70.   n=b+c;
  71.  
  72.   for(i=1;i<=n;i++)
  73.     if(i<=b)
  74.        a[i]=0;
  75.     else
  76.        a[i]=1;
  77.  
  78.   bkt();
  79.  
  80. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top