842. 排列数字 - AcWing题库
#include<iostream>
using namespace std;
int n;
const int N = 10;
int st[N];
int path[N];
void dfs(int u){
if(u == n + 1){
for(int i = 1;i <= n;i++){
cout << path[i] << " ";
}
cout << endl;
return;
}
if(u > n ) return;
for(int i = 1;i <= n;i++){
if(!st[i]){
st[i] = true;
path[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main(){
cin >> n;
dfs(1);
return 0;
}