//Author:PanDaoxi
#include <iostream>
using namespace std;
int a[11],book[11],n;
void dfs(int step){ //深搜函数
if(step==n+1){
for(int i=1;i<=n;i++){ //注意从1~n
cout<<a[i];
}
cout<<endl;
return;
}
for(int i=1;i<=n;i++){
if(book[i]==0){
a[step]=i;
book[i]=1; //使用过了
dfs(step+1);
book[i]=0; //回溯
}
}
return;
}
int main(){
cin>>n;
dfs(1);
return 0;
}
C++全排列数字
原创
©著作权归作者所有:来自51CTO博客作者PanDaoxi的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
c++ 全排列
#include#include#include#include
#include ios