C++全排列数字_开发语言

//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++全排列数字_开发语言_02