|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
换一种递归代码……可是效率并没有提高,因为重复部分没有被有效利用。- Dim sj, jg(), m%, n%, k
- Sub 香川组合递归4()
- tms = Timer
- sj = [a1].CurrentRegion: m = UBound(sj): n = UBound(sj, 2): Amn = m ^ n * (m - 1) * n
- If Amn > 65536 Then Exit Sub Else ReDim jg(Amn, n + 1): k = 0
- Call dgM("", 0)
- [a1].Offset(, n + 2).CurrentRegion = "": [a1].Offset(, n + 2).Resize(Amn, n + 2) = jg
- MsgBox k & vbCr & Format(Timer - tms, "0.000s")
- End Sub
- Sub dgM(s$, t%)
- If t = n + 1 Then
- p = Split(s, ",")
- For j = 1 To n
- jg(k, j) = sj(p(j), j)
- jg(k, 0) = jg(k, 0) & "," & jg(k, j)
- Next
- q = Split(p(n + 1), ";")
- jg(k, n + 1) = sj(q(0), q(1))
- jg(k, 0) = Mid(jg(k, 0), 2) & "," & jg(k, n + 1)
- k = k + 1
- Exit Sub
- End If
- For i = 1 To m
- If t = n Then
- For j = 1 To n
- If i <> Val(Split(s, ",")(j)) Then Call dgM(s & "," & i & ";" & j, t + 1)
- Next
- Else
- Call dgM(s & "," & i, t + 1)
- End If
- Next
- End Sub
复制代码 |
|