#include<iostream> using namespace std; const int N=10; int n; int state[N]; bool used[N]; void dfs(int u){ if(u==n+1){ for(int i=1;i<=n;i++){ cout<<state[i]<<" "; } cout<<endl; return; } for(int i=1;i<=n;i++){ if(!used[i]){ state[u]=i; used[i]=true; dfs(u+1); state[u]=0; used[i]=false; } } } int main(){ cin>>n; dfs(1); return 0; }
标签:std,排列,递归,int,dfs,枚举 From: https://www.cnblogs.com/wxzh-t/p/17278384.html