DFS-全排列
1 void dfs(int x) 2 { 3 if(x>n) 4 { 5 for(int i=1;i<=n;++i) cout<<a[i]; 6 cout<<endl; 7 return; 8 } 9 for(int i=1;i<=n;++i) 10 { 11 if(!v[i]) 12 { 13 a[x]=i;v[i]=1; 14 dfs(x+1); 15 v[i]=0; 16 } 17 } 18 } 19 int main() 20 { 21 scanf("%d",&n); 22 dfs(1); 23 return 0; 24 }