Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int st[27], n, p;
- void tipar(int k)
- {
- for (int i = 1; i <= k; i++)
- cout << (char)(st[i] + 64);
- cout << endl;
- }
- int solutie(int k)
- {
- return k == p;
- }
- void bktr()
- {
- int k = 1;
- st[k] = 0;
- while (k)
- {
- if (st[k] < n)
- {
- st[k]++;
- if (solutie(k))
- tipar(k);
- else
- {
- k++;
- st[k] = st[k - 1];
- }
- }
- else
- k--;
- }
- }
- int main ()
- {
- cin >> n >> p;
- bktr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement