#include<bits/stdc++.h>
using namespace std;
int n;
const int N = 10;
bool st[N];
int path[N];
void dfs(int u){
if(u>=n){
for(int i = 0;i<n;i++){
cout<<path[i]<<" ";
}
cout<<'\n';
}
else{
for(int i = 1;i<=n;i++){
if(st[i]==false){
st[i] = true;
path[u] = i;
dfs(u+1);
st[i] = false;
}
}
}
}
int main(){
scanf("%d",&n);
dfs(0);
}
DFS深度优先搜索
最新推荐文章于 2024-10-13 16:55:28 发布