我怎样才能找到特定字符串的组合....
ABCD - "",A,B,C,AB,AC,AD,BC,BD,CD,ABC,ACD,ABD,ABCD,...
C编程语言......
谢谢..
我怎样才能找到特定字符串的组合....
ABCD - "",A,B,C,AB,AC,AD,BC,BD,CD,ABC,ACD,ABD,ABCD,...
C编程语言......
谢谢..
在 set 中插入您需要的字母并调用 findSubset 。
Set findSubsets(Set A)
{
if A is the empty set
return the empty set
// The first element of our set is A[0]
// (A - A[0] is the set A without the first element)
Set B := findSubsets(A - A[0])
// Set B is now all the subsets of A without the first element
// We now find all the subsets of A containing the first element by finding
// tacking on the first element to the sets inside B
Set C = {}
For each set D in B
add {A[0], D} to C
return B added to C
}
在 python 中,标准库ìtertools应该有所帮助。看看combinations()
功能,也许其他的取决于你想要什么。您想允许重复吗?顺序重要吗?