public class Permutation
{
private int[] a;
public Permutation(int[] a)
{
this.a = a;
}
public boolean isOk(int b,int e){//判断是否重复
if(b < e){
for(int i = b; i < e; i++){
if(a[i] == a[e])
return false;
}
}
return true;
}
public void permutation(int k){
if(k >= a.length){
print();
}else{
for(int i = k; i < a.length; i++){
if(isOk(k,i)){
swap(i,k);
permutation( k+1 );
swap(i,k);
}
}
}
}
private void swap( int i, int k )
{
int temp = a[i];
a[i] = a[k];
a[k] = temp;
}
private void print()
{
for( int i = 0; i < a.length; i++ )
{
System.out.print(a[i] + " ");
}
System.out.println();
}
public static void main( String[] args )
{
Permutation p = new Permutation(new int[]{0,0,1,5,5,5});
p.permutation( 0 );
}
}
001555 010555 015055 015505 015550 100555 105055 105505 105550 150055 150505 150550 155005 155050 155500 005551 005515 005155 001555 555001 555010 555100 551500 515500 505501 550501
一个一个算得,望采纳