排列型枚举,输出n的全排列,用的时刘汝佳的书上的方法,
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
void solve(int *a, int cur, int n) {
if (cur == n) {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;
return;
}
for (int i = 1; i <= n; i++) {
int ok = 1;
for (int j = 0; j < cur; j++) {
if (a[j] == i) ok = 0;
}
if (ok) {
a[cur] = i;
solve(a, cur + 1, n);
}
}
}
int main() {
int n;
cin >> n;
int a[15];
solve(a, 0, n);
return 0;
}