7-20 full permutation (10 分)
there is an integer n,that means there are n numbers from 1 to n,then output the full permutation about the first n nature number.
input specification:
input one integer n.
output specification:
list the full permutation about the first n numbers with dictionary sequence,each permutation as one line.
input example:
3
output:
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
作者
严华云
单位
湖州师范学院
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include<stdio.h>
#include<iostream>
using namespace std;
int n,num[100];
int visit[100]={0};
void pailie(int t){
int i,j;
if(t>n){
for(j=1;j<=n;j++){
cout<<num[j]<<" ";
}
cout<<endl;
}
else{
for(i=1;i<=n;i++){
if(visit[i]==0){
num[t]=i;
visit[i]=1;
pailie(t+1);
visit[i]=0;
}
}
}
}
int main(){
cin>>n;
pailie(1);
}