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