增加一个,元素可重复的组合结果代码:- Dim sj, jg(), m, n, k
- Sub 元素可重复组合递归()
- tms = Timer
- m = [a1].End(4).Row
- sj = [a1].Resize(m)
- n = [b1]
- AC = WorksheetFunction.Combin(m + n - 1, n)
- ReDim jg(AC, n)
- k = 0
- Call cfzhdg("", 1, 0)
- [b3] = AC
- [d1].CurrentRegion = ""
- [d1].Resize(AC, n + 1) = jg
- [d1].Resize(, n + 1).EntireColumn.AutoFit
- MsgBox Timer - tms
- End Sub
- Sub cfzhdg(s$, i, t%)
- If t = n Then
- p = Split(s, ",")
- For j = 1 To n
- jg(k, j) = sj(p(j), 1)
- jg(k, 0) = jg(k, 0) & "," & sj(p(j), 1)
- Next
- jg(k, 0) = Mid(jg(k, 0), 2): k = k + 1: Exit Sub
- End If
- For j = i To m
- Call cfzhdg(s & "," & j, j, t + 1)
- Next j
- End Sub
复制代码 |