package util.math;public class P { /** * */ public static int[][] P_4( int di ) { int end = di - 4; int count = 1; for( int i=di; i>end; i-- ) { count*=i; } int[][] result = new int[count][]; int index = 0; for( int a=0;a<di;a++ ) for( int b=0;b<di;b++ ) { if( b != a ) for( int c=0;c<di;c++ ) { if( c != a && c != b ) for( int d=0;d<di;d++ ) { if( d != a && d != b && d != c ) { int[] four = new int[4]; four[0] = a; four[1] = b; four[2] = c; four[3] = d; result[index] = four; index++;
} } } } System.out.println( "P_4 已经结束" + result.length); return result; } /* * */ public static void main( String[] args ) { int[][] a = P_4( 4 ); for( int i=0 ; i<a.length ; i++ ) { int[] b = a[i]; for( int j=0 ; j<b.length ; j++ ) { int t = b[j]; if( t == 0 ) { System.out.print( "A " ); } if( t == 1 ) { System.out.print( "B " ); } if( t == 2 ) { System.out.print( "C " ); } if( t == 3 ) { System.out.print( "D " ); }
} System.out.println(); } } }
char[][] c ={{'A','B','C','D'},{'B','A','D','C'},{'C','D','B','A'},{'D','C','A','B'}}; int x=0;int y=0;
{
/**
*
*/
public static int[][] P_4( int di )
{
int end = di - 4;
int count = 1;
for( int i=di; i>end; i-- )
{
count*=i;
}
int[][] result = new int[count][]; int index = 0;
for( int a=0;a<di;a++ )
for( int b=0;b<di;b++ )
{
if( b != a )
for( int c=0;c<di;c++ )
{
if( c != a && c != b )
for( int d=0;d<di;d++ )
{
if( d != a && d != b && d != c )
{
int[] four = new int[4];
four[0] = a;
four[1] = b;
four[2] = c;
four[3] = d;
result[index] = four;
index++;
}
}
}
}
System.out.println( "P_4 已经结束" + result.length);
return result;
} /*
*
*/
public static void main( String[] args )
{
int[][] a = P_4( 4 );
for( int i=0 ; i<a.length ; i++ )
{
int[] b = a[i];
for( int j=0 ; j<b.length ; j++ )
{
int t = b[j];
if( t == 0 )
{
System.out.print( "A " );
}
if( t == 1 )
{
System.out.print( "B " );
}
if( t == 2 )
{
System.out.print( "C " );
}
if( t == 3 )
{
System.out.print( "D " );
}
}
System.out.println();
}
}
}
int x=0;int y=0;
for(int r=0;r<4;r++)
{
for(int z=0;z<4;z++)
{
System.out.print(c[z][r]);
}
System.out.println("");
}
ACBD
ADBC
ABDC
ADCB
ACDB
BACD
BCDA
BADC
BDCA
BCAD
BDAC
CDBA
CDAB
CADB
CABD
CBAD
CBDA
DABC
DACB
DBCA
DBAC
DCAB
DCBA
----------------------------
应该这些吧
<%!
int len=4;
int [][]a=new int[len][];
char []ch=new char[len];
String str="";
public void init()
{
for (int i=0; i<len; i++)
{
a[i]=new int[]{0,i};
}
}
public void fn(int m)
{
for (int k=0; k<len; k++)
{
if (a[k][0]==0)
{
a[k][0]=1;
ch[m]=(char)('A'+a[k][1]);
if (m==len-1)
str+=(new String(ch)+"<br>");
else
fn(m+1);
a[k][0]=0;
}
}
}
%>
<%
init();
fn(0);
out.println(str);
%>