u11 test
This commit is contained in:
parent
eebd290a9d
commit
21b3515dfe
@ -1,10 +1,17 @@
|
|||||||
from functools import lru_cache
|
|
||||||
|
|
||||||
def maximum_value(maximum_weight, items):
|
def maximum_value(maximum_weight, items):
|
||||||
for w in maximum_weight:
|
dp = [0] * (maximum_weight+1)
|
||||||
if maximum_weight < w:
|
|
||||||
continue
|
|
||||||
|
|
||||||
@lru_cache
|
for item in items:
|
||||||
def helper(i,w):
|
item_w = item['weight']
|
||||||
if i == len(items) or i == 0:
|
item_v = item['value']
|
||||||
|
|
||||||
|
for w in range(item_w, maximum_weight+1):
|
||||||
|
new_v = dp[w - item_w] + item_v
|
||||||
|
if new_v > dp[w]:
|
||||||
|
dp[w] = new_v
|
||||||
|
|
||||||
|
return dp[maximum_weight]
|
||||||
|
|
||||||
|
|
||||||
|
def maximum_value_with_items(maximum_weight, items):
|
||||||
|
pass
|
||||||
Loading…
Reference in New Issue
Block a user