求算法:有M个非重复数字,穷举其中N(n<=m)个数字组合,将这些组合输出到一个列表。
有M个非重复数字,穷举其中N(n<=m)个数字组合(不考虑排列),将这些组合输出到一个列表。 问题点数:50、回复次数:9Top
1 楼livode(啊水)回复于 2006-03-15 10:14:46 得分 0
用递归Top
2 楼flyleo()回复于 2006-03-15 10:28:42 得分 0
兄弟,我是菜鸟,给个具体的吧Top
3 楼dilong_hcj(夏雨)回复于 2006-03-15 10:57:48 得分 50
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim str As String()
str = getGroup("56455", 5)
End Sub
Private Function getGroup(ByVal str As String, ByVal Count As Integer) As String()
Dim ch As Char()
ch = CType(str, Char())
'Return ch
Dim i As Integer
Dim strGroup As String()
getGroupStr(ch, Count, strGroup)
Return strGroup
End Function
Function getGroupStr(ByVal ch As Char(), ByVal count As Integer, ByRef rtnStr As String())
Dim i, j As Integer
Dim intUbound As Integer
Dim tmpStr As String()
If rtnStr Is Nothing Then
ReDim tmpStr(UBound(ch))
ReDim rtnStr(0)
rtnStr(0) = ""
Else
ReDim Preserve tmpStr(ch.Length * rtnStr.Length - 1)
End If
For i = 0 To UBound(rtnStr)
For j = 0 To UBound(ch)
tmpStr(i * (ch.Length) + j) = rtnStr(i) & ch(j)
Next
Next
ReDim rtnStr(UBound(tmpStr))
Array.Copy(tmpStr, rtnStr, tmpStr.Length)
count = count - 1
If count = 0 Then
Exit Function
Else
getGroupStr(ch, count, rtnStr)
End If
End FunctionTop
4 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-15 12:34:34 得分 0
呵呵呵,楼上好规整的递归Top
5 楼zhengoodman(伤心小箭--甩一个人需要理由吗?)回复于 2006-03-15 13:18:29 得分 0
markTop
6 楼flyleo()回复于 2006-03-15 13:49:40 得分 0
比如说:
m=1 2 3 4
n=3
则结果应该为:
1 2 3
1 2 4
2 3 4Top
7 楼flyleo()回复于 2006-03-15 13:53:37 得分 0
麻烦 dilong_hcj(夏雨) 再改一下Top
8 楼flyleo()回复于 2006-03-15 13:54:36 得分 0
刚才写错了
比如说:
m=1 2 3 4
n=3
则结果应该为:
1 2 3
1 2 4
1 3 4
2 3 4
Top
9 楼dilong_hcj(夏雨)回复于 2006-03-17 09:40:39 得分 0
你先试着改 很简单的 如果实在不行我再帮你Top




