Advertisement
AlexandruDu

Problema Aranjamente

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