【DFS】
class Solution {
public:
int n;
int path[10000];
bool st[10000];
void dfs(int u) {
if(u==n){
for(int i=0;i<n;++i)cout<<path[i]<<" ";
cout<<endl;
return;
}
for(int i=1;i<=n;++i){
if(!st[i]){
path[u]=i;
st[i]=1;
dfs(u+1);
st[i]=0;
}
}
}
};
int main(){
auto c=Solution();
c.n=4;
c.dfs(0);
return 0;
}
标签:10000,int,void,Solution,算法,模板
From: https://www.cnblogs.com/wiaxiamm/p/17621917.html