Advertisement
STANAANDREY

combi cls op

Oct 20th, 2020
2,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int st[27], n, p;
  4.  
  5. void tipar(int k)
  6. {
  7.     for (int i = 1; i <= k; i++)
  8.         cout << (char)(st[i] + 64);
  9.     cout << endl;
  10. }
  11.  
  12. int solutie(int k)
  13. {
  14.     return k == p;
  15. }
  16.  
  17. void bktr()
  18. {
  19.     int k = 1;
  20.     st[k] = 0;
  21.     while (k)
  22.     {
  23.         if (st[k] < n)
  24.         {
  25.             st[k]++;
  26.             if (solutie(k))
  27.                 tipar(k);
  28.             else
  29.             {
  30.                 k++;
  31.                 st[k] = st[k - 1];
  32.             }
  33.         }
  34.         else
  35.             k--;
  36.     }
  37. }
  38.  
  39. int main ()
  40. {
  41.     cin >> n >> p;
  42.     bktr();
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement