dfs排列数字
#include<iostream> using namespace std; const int N=10; int path[N]; bool str[N]; int n; void dfs(int u){ if(u==n){ for(int i=0;i<n;i++)printf("%d ",path[i]); puts(" ");//换行符操作 return; } for(int i=1;i<=n;i++){ if(!str[i]){ path[u]=i; str[i]=true; dfs(u+1); str[i]=false; } } } int main(){ cin>>n; dfs(0); return 0; }
标签:排列,21,int,dfs,皇后,数字 From: https://www.cnblogs.com/daimazhishen/p/17721043.html