元素中所有元素的组合,每个元素中只有一个元素 [英] All Combinations of Elements with Exactly One Element from Each Group
本文介绍了元素中所有元素的组合,每个元素中只有一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法来获取所有可能的组合,这些组合由每个组中的一个完全相同的元素组成.出于我的目的,我不在乎元素的顺序.我的意思是{1,2}与{2,1}相同.
I am looking for a way to get all possible combinations consisting of exactly one element from each group. For my purposes, I do not care about the ordering of the elements. By that I mean {1,2} is the same as {2,1}.
假设我有以下4个小组:
Suppose I had the following 4 groups:
Group 1 = {e1, e2}
Group 2 = {e3, e4}
Group 3 = {e5, e6, e7}
Group 4 = {e8}
在这种情况下,我想我想(假设实际上是所有唯一的组合)
In this case, I think I would want (assuming that actually is all unique combinations)
{e1, e3, e5, e8}
{e1, e3, e6, e8}
{e1, e3, e7, e8}
{e1, e4, e5, e8}
{e1, e4, e6, e8}
{e1, e4, e7, e8}
{e2, e3, e5, e8}
{e2, e3, e6, e8}
{e2, e3, e7, e8}
{e2, e4, e5, e8}
{e2, e4, e6, e8}
{e2, e4, e7, e8}
我应该如何解决这样的问题?我的希望是,即使只是提示也可以帮助我.
How should I approach a problem such as this? My hope is that even just a hint should help me out a ton.
推荐答案
for (var Item1 in Group1) {
for (var Item2 in Group2) {
for (var Item3 in Group3) {
for (var Item4 in Group4) {
echo '{'+Item1+','+Item2+','+Item3+','+Item4+')';
}
}
}
}
这篇关于元素中所有元素的组合,每个元素中只有一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文