Files
python/TangDou/AcWing/Dfs/842.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

33 lines
566 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
int a[N], al;
bool st[N];
void dfs(int u) {
// 如果到达了终点
if (u == n + 1) {
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
puts("");
return;
}
for (int i = 1; i <= n; i++)
if (!st[i]) {
a[al++] = i;
st[i] = true;
dfs(u + 1);
st[i] = false;
al--;
}
}
int main() {
cin >> n;
// 开始
dfs(1);
return 0;
}