从多个数组生成所有可能的组合(C#/VB.NET) [英] Generate all possible combinations from multiple arrays (C#/VB.NET)

查看:42
本文介绍了从多个数组生成所有可能的组合(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 … … … … … … … … … … … …

推荐答案

基于

输出:

(a,1,x), (a,1,y), (a,1,z), (a,2,x), (a,2,y), (a,2,z), (b,1,x), (b,1,y), (b,1,z), (b,2,x), (b,2,y), (b,2,z), (c,1,x), (c,1,y), (c,1,z), (c,2,x), (c,2,y), (c,2,z)

这篇关于从多个数组生成所有可能的组合(C#/VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆