小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

递归实现数字排列组合

参考彭希仁的递归算法

Sub macro1()
Dim arr() As String
getall 9, 3, "", arr
Debug.Print Join(arr, ",")
End Sub
Sub getall(ByVal m As Byte, ByVal n As Byte, ByRef a As String, ByRef arr() As String, Optional ByRef count As Long)
    If Len(a) = n Then
        count = count + 1
        ReDim Preserve arr(1 To count)
        arr(count) = a
        Exit Sub
    End If
    For i = 0 To m 'Val(Right(a, 1)) To m
        If InStr(a, i) = 0 Then getall m, n, a & i, arr, count
    Next i
End Sub 

posted on 2007-10-30 16:33  王峰炬  阅读(192)  评论(0编辑  收藏  举报

导航