【发布时间】:2013-09-09 14:10:44
【问题描述】:
我需要找到一个像这样工作的函数:
int[] matches = getAllPossibleCombinations(
int lengthOfEachIntReturnedInArray,
List<char> typesOfElementsUsedInCombinations);
输入元素是这些(这只是一个例子):
int lengthofeachintreturnedinarray = (int) 2List<char> typesofelementsusedincombinations = {a,b}
那么输出必须是(在字符串数组中):
啊
ab
巴
bb
数组中的每个单独的输出元素必须具有由方法中的第一个参数定义的长度(在本例中为 2),并且必须包含第二个参数中给定字母之间的所有可能组合
我看到了一些关于 powerset 的东西,我应该使用它们,还是应该 foreach 循环适合这项工作?
!建议的问题与上面的答案不一样,它不使用设置长度!
【问题讨论】:
-
你有什么要求这样做
-
与原子结合(化学)
-
您希望第二个参数是
List<string>还是List<char>?即,单个元素可以有多个字符吗? -
你是对的 - 我将其更改为 List
;谢谢!
标签: c# .net string combinations combinatorics