题目
分析
代码
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 const int N = 7; 5 6 bool st[N]; 7 int path[N]; 8 9 void dfs(int n,int u){ 10 if(u == n){ 11 for(int i = 0;i < n;i++){ 12 printf("%d ",path[i]); 13 } 14 puts(""); 15 } 16 for(int i = 1 ;i <= n;i++){ 17 if(!st[i]){ 18 path[u] = i; 19 st[i] = true; 20 dfs(n,u+1); 21 path[u] = 0; 22 st[i] = false; 23 } 24 } 25 } 26 27 int main(){ 28 int n; 29 cin>>n; 30 dfs(n,0); 31 return 0; 32 33 }