1,数组的个数不确定(比如10个数组);
2,每个数组的元素个数也不确定;
3,每个数组取一个数与其他所有数组取出的数进行组合
 请提供用C#来实现的算法
比如下面的三个数组
int[] a = { 1, 2, 3, 4, 5 };
int[] b = { 6, 7, 8, 9 };
int[] c = { 10, 11, 12 };
 从三组数中分别取一个数进行组合,如{1,6,10},{1,6,11},{1,6,12},{1,7,10}..... 
不需要考虑数字排列顺序,每组中的元素只能与其他组中的元素进行组合, 

解决方案 »

  1.   

    有点麻烦,不过可以实现:        static void Main(string[] args)
            {
                int[] a = { 1, 2, 3, 4, 5 };
                int[] b = { 6, 7, 8, 9 };
                int[] c = { 10, 11, 12 };
                int[] d = { 13, 14 };
                int[] e = { 15, 16, 17, 18 };
                Matrix m1 = new Matrix(Array.ConvertAll<int, string>(a, Convert.ToString));
                m1 = m1.Multiply(new Matrix(Array.ConvertAll<int, string>(b, Convert.ToString)));
                m1 = m1.Multiply(new Matrix(Array.ConvertAll<int, string>(c, Convert.ToString)));
                m1 = m1.Multiply(new Matrix(Array.ConvertAll<int, string>(d, Convert.ToString)));
                m1 = m1.Multiply(new Matrix(Array.ConvertAll<int, string>(e, Convert.ToString)));
                foreach (string s in m1.element)
                    Console.WriteLine(s);
            }        struct Matrix
            {
                public string[] element;
                public Matrix(string[] s)
                {
                    element = s;
                }
                public Matrix Multiply(Matrix m)
                {
                    string[] s = new string[this.element.Length * m.element.Length];
                    int index = 0;
                    for (int i = 0; i < this.element.Length; i++)
                    {
                        for (int j = 0; j < m.element.Length; j++)
                        {
                            s[index] = this.element[i] + "," + m.element[j];
                            index++;
                        }
                    }
                    return new Matrix(s);
                }
            }
        }
      

  2.   

    我在http://topic.csdn.net/u/20080901/10/e481d4e0-2a25-4d0d-8abb-53ac1a4b5ae7.html给你回帖了。
      

  3.   

    using System;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] a = { 1, 2, 3, 4, 5 };
                int[] b = { 6, 7, 8, 9 };
                int[] c = { 10, 11, 12 };
                int[] d = { 13, 14 };
                int[] e = { 15, 16, 17, 18 };
                OutputCombinatorial(a, b, c, d, e);
            }        private static void OutputCombinatorial(params int[][] arrays)
            {
                int[] indexes = new int[arrays.Length];            int i = indexes.Length - 1;
                while (i > -1)
                {
                    OutputOneCombination(arrays, indexes);
                    i = indexes.Length - 1;
                    indexes[i]++;
                    while (indexes[i] == arrays[i].Length)
                    {
                        indexes[i] = 0;
                        i--;
                        if (i == -1)
                        {
                            break;
                        }                    indexes[i]++;
                    }
                }
            }        private static void OutputOneCombination(int[][] arrays, int[] indexes)
            {
                for (int i = 0; i < indexes.Length; i++)
                {
                    Console.Write(arrays[i][indexes[i]].ToString() + " ");
                }
                Console.WriteLine();
            }
        }
    }