-
递归列举从数组b()中选出某些元素(允许重复)使其和等于num的所有组合
- Dim mycount As Long, s(1 To 65536, 1 To 1), num As Long
- Sub main()
- Dim a, b
- num = 45
- b = Array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
- ReDim a(num)
- a(0) = b(0)
- search num, 0, 0, a, b
- [a1].Resize(65536) = s
- MsgBox "OK", , "Total count=" & mycount
- End Sub
- Sub search(ByVal n As Long, ByVal j As Long, ByVal index As Long, ByRef a, ByRef b)
- For i = index To UBound(b)
- If n = b(i) Then
- mycount = mycount + 1
- a(j) = b(i)
- For k = 0 To j
- s(mycount, 1) = s(mycount, 1) & " " & a(k)
- Next
- s(mycount, 1) = Replace(Trim(s(mycount, 1)), " ", "+") & "=" & num
- Else
- a(j) = b(i)
- If n >= b(i) Then search n - b(i), j + 1, i, a, b
- End If
- Next
- End Sub
-
相关阅读:
md5加密排序
md5加密
PHP获取文件后缀名
PHP中使用CURL实现GET、POST、PUT、DELETE请求
PHP常用正则表达式精选
19 个让 MySQL 效率提高 3 倍的 SQL 优化技巧
git clone、 remote、fetch、pull、push、remote
git 命令常用笔记
十个推荐使用的 Laravel 的辅助函数
PHP常用函数大全500+
-
原文地址:https://www.cnblogs.com/fengju/p/6336261.html
Copyright © 2020-2023
润新知