【发布时间】:2012-12-04 08:50:12
【问题描述】:
string[] array = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"};
如何使用组合公式 nCr = 10!/2!(10- 2)! = 45 种组合。
我需要这样的输出:
"01", "02"
"01", "03"
"01", "04"
...
"02", "03" // eliminate the "02","01" 'cause it is same as "01","02" combination
"02", "04"
...
然后生成 3 个字符串的组合,将有 120 个组合(根据 nCr)。 我需要输出是这样的:
"01","02","03"
"01","02","04"
...
4 个字符串的组合,将有 210 个组合,最少,每个组合 5 个字符串的组合,将有 252 个组合。
我该怎么写?我用了很多循环,看起来真的很乱。
【问题讨论】:
-
我什么都不懂,但能帮到你吗?使用两个数字获得 ncr 组合的功能:programmingsimplified.com/c/source-code/… 或:dreamincode.net/code/snippet2334.htm
-
我需要组合,而不是全部组合
-
@TheMouthofaCow 类似,但不一样。
标签: c# arrays algorithm combinations