//The algorithm of full arrangement from the teacher ZhengLiu
import java.util.*;
class Deal{
int n;
int count=0;
int array[];
Deal(int n){
this.n=n;
array= new int[n+1];
for(int i=1;i<=n;i++)
array[i]=i;
}
void arrange(int loc){//arrange
if(loc==1){
count++;
//for(int i=1;i<=n;i++)
//System.out.printf("%d%c",array[i],i==n?'\n':' ');
}
else{
for(int i=1;i<=loc;i++){
change(loc,i);
arrange(loc-1);
change(loc,i);
}
}
}
void change(int start,int end){//swap the two numbers
int temp=array[start];
array[start]=array[end];
array[end]=temp;
}
}
class FullArrange{
public static void main(String []args){
int n;
//Scanner reader = new Scanner(System.in);
//n=reader.nextInt();
for(n=1;n<=10;n++){//everytime output the sum of different arrangements from 1 to n
Deal deal=new Deal(n);
deal.arrange(n);
System.out.println(deal.count);
}
}
}
全排列
最新推荐文章于 2025-03-10 22:27:24 发布