- ©«¤l
- 1018
- ¥DÃD
- 15
- ºëµØ
- 0
- ¿n¤À
- 1058
- ÂI¦W
- 0
- §@·~¨t²Î
- win7 32bit
- ³nÅ骩¥»
- Office 2016 64-bit
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ®ç¶é
- µù¥U®É¶¡
- 2012-5-9
- ³Ì«áµn¿ý
- 2022-9-28
|
¦^´_ 1# qmi - Sub Test()
- Dim arInput, flagTake
- Dim dResult As Object: Set dResult = CreateObject("scripting.dictionary")
-
- arInput = Range("A1").CurrentRegion.Value
- ReDim flagTake(LBound(arInput, 2) To UBound(arInput, 2)) As Boolean 'true=¨ú ; false=¤£¨ú
-
- backtrack arInput, flagTake, 1, 0, dResult
-
- Range("E:F").ClearContents
- Range("E4").Resize(dResult.count).Value = Application.Transpose(dResult.keys)
- Range("F4").Resize(dResult.count).Value = Application.Transpose(dResult.items)
- End Sub
- Sub backtrack(ByRef arInput, ByRef flagTake, n As Integer, cost As Double, ByRef dResult As Object)
- Dim i As Integer, strOut As String
-
- If cost > 0 And cost <= 105 Then
- For i = LBound(arInput, 2) To UBound(arInput, 2)
- If Len(strOut) = 0 Then
- strOut = IIf(flagTake(i), arInput(1, i), "")
- Else
- strOut = strOut & IIf(flagTake(i), "+" & arInput(1, i), "")
- End If
- Next
- dResult.Add strOut, cost 'push to result
- End If
-
- For i = n To UBound(arInput, 2)
- flagTake(i) = True
- backtrack arInput, flagTake, i + 1, cost + arInput(2, i), dResult
- flagTake(i) = False '¦^´_flag
- Next
- End Sub
½Æ»s¥N½X |
|