|
楼主 |
发表于 2013-9-17 14:23
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
2013年最新研究成果:
世上最快速度的Excel VBA 组合算法核心部分:- Function CombinDo(ByVal m&, ByVal n&)
- Dim i&, j&, k&
- tms = Timer
- ReDim a&(1 To n)
- For j = 1 To n - 1
- a(j) = j
- Next
-
- k = 0: i = n - 1 ': j = n
- Do
- For i = i + 1 To m
- ' a(j) = i
- k = k + 1
- Next
-
- For j = j - 1 To 1 Step -1
- i = a(j) + 1: a(j) = i
- If i = m - n + j Then
- k = k + 1
- Else
- j = j + 1
- Do Until j = n
- i = i + 1: a(j) = i: j = j + 1
- Loop
- If i = m Then Exit Do Else Exit For
- End If
- Next
- Loop Until j = 0
-
- CombinDo = Format(Timer - tms, "0.000s ") & k
- End Function
复制代码 计算下面1千万的组合只要1.723秒。(我这用的是低配置电脑)
1.723s Combin(26,13)= 10400600
|
|