u11 update

This commit is contained in:
Maksym Kurets 2026-12-04 22:19:02 +01:00
parent d65bbb5a5f
commit b69ca78df5

View File

@ -26,17 +26,17 @@ def maximum_value_with_items(maximum_weight, items):
stav = {0: (0,[])} stav = {0: (0,[])}
for item in items: for item in items:
w = item["weight"] w = item["weight"]
v = item["value"] v = item["value"]
Novystav = dict(stav) Novystav = dict(stav)
for currW,(currV, vibir) in stav.items(): for currW,(currV, vibir) in stav.items():
NEwW = currW + w NEwW = currW + w
if NEwW <= maximum_weight: if NEwW <= maximum_weight:
NewV = currV + v NewV = currV + v
if NewV > Novystav.get(NEwW, (0, []))[0]: if NewV > Novystav.get(NEwW, (0, []))[0]:
Novystav[NEwW] = (NewV, vibir + [item]) Novystav[NEwW] = (NewV, vibir + [item])
stav = Novystav stav = Novystav