new file: 8.cpp
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
// 94
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const int N = 20;
|
||||||
|
int n;
|
||||||
|
bool st[N]; // 数字是否用过
|
||||||
|
int path[N]; // 保存数列
|
||||||
|
|
||||||
|
void dfs(int cnt)
|
||||||
|
{
|
||||||
|
if (cnt > n)
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
printf("%d ", path[i]);
|
||||||
|
puts("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
{
|
||||||
|
if (!st[i])
|
||||||
|
{
|
||||||
|
path[cnt] = i, st[i] = 1;
|
||||||
|
dfs(cnt + 1);
|
||||||
|
path[cnt] = 0, st[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
scanf("%d", &n);
|
||||||
|
dfs(1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user