Advertisement
Guest User

aranjamente si combinari

a guest
Feb 15th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. //aranjamente
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int x[200],n,k,p;
  7.  
  8. int cont(int k)
  9. {
  10.     for(int i=1;i<k;i++)
  11.     {
  12.         if(x[i]==x[k])
  13.             return 0;
  14.     }
  15.     return 1;
  16. }
  17.  
  18. void tipar(int k)
  19. {
  20.     for(int i=1;i<=k;i++)
  21.     {
  22.         cout<<x[i]<<" ";
  23.     }
  24.     cout<<endl;
  25. }
  26.  
  27. void bkt()
  28. {
  29.     k=1;
  30.     x[k]=0;
  31.  
  32.     while(k>0)
  33.     {
  34.         if(x[k]<n)
  35.         {
  36.             x[k]++;
  37.             if(cont(k))
  38.             {
  39.                 if(k==p)
  40.                     tipar(k);
  41.                 else
  42.                 {
  43.                     k++;
  44.                     x[k]=0;
  45.                 }
  46.             }
  47.         }
  48.         else k--;
  49.     }
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55.     cin>>n>>p;
  56.     bkt();
  57.     return 0;
  58. }
  59. //combinari
  60. #include <iostream>
  61.  
  62. using namespace std;
  63.  
  64. int x[200],n,k,p;
  65.  
  66. int cont(int k)
  67. {
  68.    /* for(int i=1;i<k;i++)
  69.     {
  70.         if(x[i]>=x[k])
  71.             return 0;
  72.     }*/
  73.     return 1;
  74. }
  75.  
  76. void tipar(int k)
  77. {
  78.     for(int i=1;i<=k;i++)
  79.     {
  80.         cout<<x[i]<<" ";
  81.     }
  82.     cout<<endl;
  83. }
  84.  
  85. void bkt()
  86. {
  87.     k=1;
  88.     x[k]=0;
  89.  
  90.     while(k>0)
  91.     {
  92.         if(x[k]<n)
  93.         {
  94.             x[k]++;
  95.             if(cont(k))
  96.             {
  97.                 if(k==p)
  98.                     tipar(k);
  99.                 else
  100.                 {
  101.                     k++;
  102.                     x[k]=x[k-1];
  103.                 }
  104.             }
  105.         }
  106.         else k--;
  107.     }
  108. }
  109.  
  110. int main()
  111. {
  112.  
  113.     cin>>n>>p;
  114.     bkt();
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement