dfs
#include <iostream>
using namespace std;
const int N = 10;//存1-9的数
int n;
void dfs(int u,int nums[],bool st[])
{
if(u > n)//边界条件
{
for (int i = 1; i <= n;i ++)
cout << nums[i] << " ";
cout << endl;
}
else
{
for (int i = 1; i <= n;i ++)//循环条件
{
if(!st[i])
{
st[i] = true;
nums[u] = i;
dfs(u + 1, nums, st);
st[i] = false;//恢复现场
}
}
}
}
int main()
{
cin >> n;
int nums[N];//整数数组
bool st[N] = {0};//判断数组
dfs(1,nums,st);
}