English 中文(简体)
如何在C++的一个阵列中列出所有可能的组合?
原标题:How to list all the possible sums of combinations in an array for C++?

我有自己的工作任务,我不知道如何开始处理此类问题。

请允许我说,我有一阵列,由零件组成。

[A][B][C][D][E](例如,我们有5个要素)

I want to list out all the sum of possibility such that I want to print out the sum of all combination (ABCDE, ABCD, ABCE, ACDE, BCDE, ABC, ABD, ABE, ACE, ADE, BDE, CDE, AB, AC, AD, AE, BC, BD, BE, CD, CE, DE, A, B, C, D and E)

另一个实例是阵列中的4个要素([A][B][C][D])

我想列出所有组合(ABCD、ABC、ABD、ACD、BCD、AB、AC、 AD、BCP、BD、CD、A、B、C和D)。

最佳回答

Well, here s a simple rule to follow:

“ABCDE”的所有组合由包含(并由此开始)“A”和不含“A”的组合组成。 在这两种情况下,“BCDE”的所有组合都会发生。 当然,“BCDE”的组合可以用同样的方式处理。

问题回答

When you say "list out all the sum of possibility" do you mean you want to know how many combinations are actually possible?

如果是的话,那么就搜查了当时从K手中夺取的N项物品的组合;在这个网站上有处理该问题的网页。 然后,你只增加(五)+(四)+(三)+(二)+(一)+(一)+(一)的组合数目,以获得你的“全部可能性”。

或者,你是否意味着你们有一系列的价值观,你真的想勾画出不同要素组合所代表的不同数额? 在这种情况下,你需要实际列举所有组合,并评估数额。

因此,鉴于第1、2、3、4、5}号决议,你可以将其编成“A”、“B”、“C”、“D”、“E”。 例如:

  • ABCDE = 1+2+3+4+5
  • ABE = 1+2+5
  • BCE = 2+3+5

等等,如果你使用编码的点数来遴选您的增量。 请注意,决定是否允许或消除重复(即“DE”不同于“ED”),将对你的成果产生巨大影响;在大多数情况下,这可能是not?

如果你有3个要素,你可以想象把每个要素放在1至3个(或0至2个)的位置上,并设想一个显示该要素是否包含在某一组别中的蓝色阵列。

ABC remark
--- ---------------------
000 no element in the set
001 one element, C
010 one element, b
100 ...
011 two elements, b and c
...
111 all elements contained

现在,如果你计算解决办法数目(即23个),并产生一种功能,即从双亲代表处绘制到一组,从011个到(b、c)不等,那么你可以很容易地规划一种照样,从0个到最高1个不等,并按你的绘图功能制作。





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签