|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
嵌套使用2个递归组合算法。
- Dim sj1, sj2, jg(), dic, m1&, m2&, n&, k&
- Sub test() 'by kagawa 2015/5/11
- Dim tms#
- tms = Timer
- m1 = [a1].End(4).Row - 1: sj1 = [a2].Resize(m1)
- m2 = [b1].End(4).Row - 1: sj2 = [b2].Resize(m2)
- n = [g2]: If n = 0 Then n = 35 Else n = n + 2
-
- ReDim jg(65530, 1)
- k = 0: Call dgQZH1("", 0, 0)
-
- MsgBox Format(Timer - tms, "0.000s ") & k
- [d1].CurrentRegion.Offset(1) = "": [d2].Resize(k, 2) = jg
- End Sub
- Sub dgQZH1(s$, j&, t&)
- Dim i&
- If t > 1 Then If Len(s) < n Then Call dgQZH2(s, 0, 0) Else Exit Sub
-
- For i = j + 1 To m1
- Call dgQZH1(s & " " & sj1(i, 1), i, t + 1)
- Next
- End Sub
- Sub dgQZH2(s$, j&, t&)
- Dim i&
- If Len(s) < n Then jg(k, 0) = Mid(s, 2): jg(k, 1) = Len(s) - 1: k = k + 1 Else Exit Sub
-
- For i = j + 1 To m2
- Call dgQZH2(s & " " & sj2(i, 1), i, t + 1)
- Next
- End Sub
复制代码 |
|