//求1~5的全排列
#include <iostream>
#include <cstdio>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int a[5],book[5];
void dfs(int step)
{
if(step==5)
{
for(int i=0;i<5;i++)
{
printf("%d",a[i]);
}
printf("\n");
return ;
}
for(int i=1;i<=5;i++)
{
if(book[i]==0)
{
a[step]=i;
book[i]=1;
dfs(step+1);
book[i]=0;
}
}
return;
}
int main(int argc, char *argv[]) {
dfs(0);
return 0;
}
//全排列可以用algorithm下的next_permutation