From 0aec79bef8012ccd565c46191783b7d81a0cf2ec Mon Sep 17 00:00:00 2001 From: Maksym Kurets Date: Fri, 4 Dec 2026 22:03:57 +0100 Subject: [PATCH] u11 update --- u11/knapsack.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/u11/knapsack.py b/u11/knapsack.py index 9f807d2..a0cc91c 100644 --- a/u11/knapsack.py +++ b/u11/knapsack.py @@ -2,7 +2,7 @@ def maximum_value(maximum_weight, items): if not items or maximum_weight <= 0: return 0 - stav = {0, 0} + stav = {0: 0} for item in items: w = item["weight"] @@ -10,7 +10,7 @@ def maximum_value(maximum_weight, items): Novystav = dict(stav) for currW, currV in stav.items(): - NEwW = currW + W + NEwW = currW + w if NEwW <= maximum_weight: NewV = currV + v if NewV > Novystav.get(NEwW, 0): @@ -31,7 +31,7 @@ def maximum_value_with_items(maximum_weight, items): v = item["value"] Novystav = dict(stav) - for currW, currV in stav.items(): + for currW,(currV, vibir) in stav.items(): NEwW = currW + W if NEwW <= maximum_weight: NewV = currV + v @@ -40,12 +40,12 @@ def maximum_value_with_items(maximum_weight, items): stav = Novystav - BV = 0 - Bvibir = [] - for v, vibir in stav.values(): - if v >BV: - BV = v - Bvibir = vibir + BV = 0 + Bvibir = [] + for v, vibir in stav.values(): + if v >BV: + BV = v + Bvibir = vibir return BV, Bvibir