u11 test4
This commit is contained in:
parent
34f35fb827
commit
3e279617c5
@ -14,4 +14,16 @@ def maximum_value(maximum_weight, items):
|
|||||||
|
|
||||||
|
|
||||||
def maximum_value_with_items(maximum_weight, items):
|
def maximum_value_with_items(maximum_weight, items):
|
||||||
pass
|
dp = [0] * (maximum_weight + 1)
|
||||||
|
choose = [] * (maximum_weight + 1)
|
||||||
|
for item in items:
|
||||||
|
item_w = item['weight']
|
||||||
|
item_v = item['value']
|
||||||
|
|
||||||
|
for w in range(maximum_weight, item_w -1, -1):
|
||||||
|
new_v = dp[w - item_w] + item_v
|
||||||
|
if new_v > dp[w]:
|
||||||
|
dp[w] = new_v
|
||||||
|
choose[w] = choose[w - item_w] + item_v
|
||||||
|
|
||||||
|
return dp[maximum_weight], choose[maximum_weight]
|
||||||
Loading…
Reference in New Issue
Block a user