首页  编辑  

矩阵组合

Tags: /C#/算法/   Date Created:

string [,] vList = {

   { "a1" , "b1" , "c1" , "d1" },

   { "a2" , "b2" , "c2" , "d2" },

   { "a3" , "b3" , "c3" , "d3" } };

int [] vIndexs = new int [vList . GetLength( 1 )];

for ( int k = 0 ; k < vList . GetLength( 1 ); k ++ )

   vIndexs[k] = 0 ;

bool vBreak = false ;

do

{

    for ( int j = 0 ; j < vList . GetLength( 1 ); j ++ )

       textBox1 . AppendText(vList[vIndexs[j], j]);

   textBox1 . AppendText( "\r\n" );

   vBreak = true ;

    for ( int j = 0 ; j < vList . GetLength( 1 ); j ++ )

        if (vIndexs[j] + 1 < vList . GetLength( 0 ))

       {

           vIndexs[j] ++ ;

            for ( int i = 0 ; i < j; i ++ ) vIndexs[i] = 0 ;

           vBreak = false ;

            break ;

       }

}

while ( ! vBreak);

---------

a1b1c1d1

a2b1c1d1

a3b1c1d1

a1b2c1d1

a2b2c1d1

a3b2c1d1

a1b3c1d1

a2b3c1d1

a3b3c1d1

a1b1c2d1

a2b1c2d1

a3b1c2d1

a1b2c2d1

a2b2c2d1

a3b2c2d1

a1b3c2d1

a2b3c2d1

a3b3c2d1

a1b1c3d1

a2b1c3d1

a3b1c3d1

a1b2c3d1

a2b2c3d1

a3b2c3d1

a1b3c3d1

a2b3c3d1

a3b3c3d1

a1b1c1d2

a2b1c1d2

a3b1c1d2

a1b2c1d2

a2b2c1d2

a3b2c1d2

a1b3c1d2

a2b3c1d2

a3b3c1d2

a1b1c2d2

a2b1c2d2

a3b1c2d2

a1b2c2d2

a2b2c2d2

a3b2c2d2

a1b3c2d2

a2b3c2d2

a3b3c2d2

a1b1c3d2

a2b1c3d2

a3b1c3d2

a1b2c3d2

a2b2c3d2

a3b2c3d2

a1b3c3d2

a2b3c3d2

a3b3c3d2

a1b1c1d3

a2b1c1d3

a3b1c1d3

a1b2c1d3

a2b2c1d3

a3b2c1d3

a1b3c1d3

a2b3c1d3

a3b3c1d3

a1b1c2d3

a2b1c2d3

a3b1c2d3

a1b2c2d3

a2b2c2d3

a3b2c2d3

a1b3c2d3

a2b3c2d3

a3b3c2d3

a1b1c3d3

a2b1c3d3

a3b1c3d3

a1b2c3d3

a2b2c3d3

a3b2c3d3

a1b3c3d3

a2b3c3d3

a3b3c3d3