diff --git a/u11/knapsack.py b/u11/knapsack.py index d253d8a..0382440 100644 --- a/u11/knapsack.py +++ b/u11/knapsack.py @@ -26,18 +26,18 @@ def maximum_value_with_items(maximum_weight, items): stav = {0: (0,[])} - for item in items: - w = item["weight"] - v = item["value"] - Novystav = dict(stav) + for item in items: + w = item["weight"] + v = item["value"] + Novystav = dict(stav) - for currW,(currV, vibir) in stav.items(): - NEwW = currW + w + for currW,(currV, vibir) in stav.items(): + NEwW = currW + w if NEwW <= maximum_weight: NewV = currV + v if NewV > Novystav.get(NEwW, (0, []))[0]: - Novystav[NEwW] = (NewV, vibir + [item]) - + Novystav[NEwW] = (NewV, vibir + [item]) + stav = Novystav BV = 0