Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define NMAX 20
- using namespace std;
- int n, c1, c2, st[NMAX], used[NMAX];
- void display() {
- for (int i = 1; i <= n; i++)
- cout << st[i] << ' ';
- cout << endl;
- }
- void bktr(int k) {
- if (k == n + 1)
- display();
- else if (k != 2 && k != n - 1) {
- for (int i = 1; i <= n; i++)
- if (!used[i]) {
- used[i] = 1;
- st[k] = i;
- bktr(k + 1);
- used[i] = 0;
- }
- } else
- bktr(k + 1);
- }
- int main () {
- cin >> n >> c1 >> c2;
- st[2] = c1, st[n - 1] = c2;
- used[c1] = used[c2] = 1;
- bktr(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement