Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define MAX 20
- using namespace std;
- int n, count;
- int Bool[MAX] = { 0 };
- int A[MAX];
- void xuat() {
- cout << endl << ++count << ": ";
- for (int i = 1; i <= n; i++)
- cout << A[i] << " ";
- cout << endl;
- }
- void Try(int k) {
- for (int i = 1; i <= n; i++) {
- if (!Bool[i]) {
- A[k] = i;
- Bool[i] = 1;
- if (k == n)
- xuat();
- else
- Try(k + 1);
- Bool[i] = 0;
- }
- }
- }
- int main() {
- cout << "Nhap n: ";
- cin >> n;
- cout << "Cac hoan vi: " << endl;
- Try(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment