Advertisement
STANAANDREY

aranjamente cls

Oct 20th, 2020
1,869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 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. int validare(int k)
  18. {
  19.     for (int i = 1; i < k; i++)
  20.         if (st[i] == st[k])
  21.             return 0;
  22.     return 1;
  23. }
  24.  
  25. void bktr()
  26. {
  27.     int k = 1;
  28.     st[k] = 0;
  29.     while (k)
  30.     {
  31.         if (st[k] < n)
  32.         {
  33.             st[k]++;
  34.             if (validare(k))
  35.             {
  36.                 if (solutie(k))
  37.                     tipar(k);
  38.                 else
  39.                 {
  40.                     k++;
  41.                     st[k] = 0;
  42.                 }
  43.             }
  44.         }
  45.         else
  46.             k--;
  47.     }
  48. }
  49.  
  50. int main ()
  51. {
  52.     cin >> n >> p;
  53.     bktr();
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement