This commit is contained in:
Volodymyr Baliasnikov 2026-12-01 20:25:03 +01:00
parent eebd290a9d
commit 21b3515dfe

View File

@ -1,10 +1,17 @@
from functools import lru_cache
def maximum_value(maximum_weight, items):
for w in maximum_weight:
if maximum_weight < w:
continue
dp = [0] * (maximum_weight+1)
@lru_cache
def helper(i,w):
if i == len(items) or i == 0:
for item in items:
item_w = item['weight']
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