从多个数组生成所有可能的组合(C#/VB.NET) [英] Generate all possible combinations from multiple arrays (C#/VB.NET)
问题描述
我有 n 个数组,每个数组可能包含 n 个元素.我必须通过从每个数组中选取一个元素来生成所有可能的值组合.
I have n number of arrays and each array may contain n number of elements. I have to generate all possible combination of values by taking one element from each array.
我需要C#/VB.NET语言的帮助.
I need help in C#/VB.NET language.
下面是一个例子.
Arr1:(a,b,c)Arr2:(1,2)Arr3:(x,y,z)
Arr1: ( a, b, c ) Arr2: ( 1, 2 ) Arr3: ( x, y, z )
我希望组合为(会有3 * 2 * 3 = 18个组合)a1x a1y a1za2x a2y a2zb1x b1y b1zb2x b2y b2zc1x c1y c1zc2x c2y c2z
I want the combinations as (There will be 3*2*3 = 18 combinations) a1x a1y a1z a2x a2y a2z b1x b1y b1z b2x b2y b2z c1x c1y c1z c2x c2y c2z
如果我有4个数组,将有36个组合.Arr1:(a,b,c)Arr2:(1,2)Arr3 :( x,y,z)Arr4 :( m,n)
if I have 4 arrays, there will be 36 combinations. Arr1: ( a, b, c ) Arr2: ( 1, 2 ) Arr3: ( x, y, z ) Arr4: ( m, n )
组合:
a1xm a1xn a1ym a1yn a1zm a1zn………………………………
a1xm a1xn a1ym a1yn a1zm a1zn … … … … … … … … … … … …