|
楼主 |
发表于 2014-10-23 22:10
|
显示全部楼层
核心的递归代码:
- Sub DG(k%, xzwc As Boolean)
- Dim j&, i&
- If pd Then Exit Sub '找到匹配结果时直接逐层返回
- If k = n Then
- For j = sl(k, 1) To 0 Step -1
- If xzwc Then
- If Abs(je(k) - dj(k, 1) * j) <= wcz Then '误差匹配
- pd = True
- ss(k) = j
- For i = 1 To n
- s = s & "-" & ss(i)
- Next i
- End If
- Else
- If je(k) - dj(k, 1) * j = 0 Then '精确匹配
- pd = True
- ss(k) = j
- For i = 1 To n
- s = s & "-" & ss(i)
- Next i
- End If
- End If
- Next j
- Else
- For j = sl(k, 1) To 0 Step -1
- je(k + 1) = je(k) - dj(k, 1) * j '下层金额=本层金额-本层单价*本层数量
- sl(k + 1, 1) = je(k + 1) \ dj(k + 1, 1) '下层数量=下层金额\下层单价
- ss(k) = j
- DG k + 1, wc
- Next j
- End If
- End Sub
复制代码
|
|