u11 update
This commit is contained in:
parent
0aec79bef8
commit
202bfd9b38
@ -22,17 +22,18 @@ def maximum_value(maximum_weight, items):
|
||||
|
||||
def maximum_value_with_items(maximum_weight, items):
|
||||
if not items or maximum_weight <= 0:
|
||||
return 0, []
|
||||
|
||||
return 0, []
|
||||
|
||||
stav = {0: (0,[])}
|
||||
|
||||
for item in items:
|
||||
w = item["weight"]
|
||||
v = item["value"]
|
||||
Novystav = dict(stav)
|
||||
w = item["weight"]
|
||||
v = item["value"]
|
||||
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:
|
||||
NewV = currV + v
|
||||
if NewV > Novystav.get(NEwW, (0, []))[0]:
|
||||
@ -44,8 +45,8 @@ def maximum_value_with_items(maximum_weight, items):
|
||||
Bvibir = []
|
||||
for v, vibir in stav.values():
|
||||
if v >BV:
|
||||
BV = v
|
||||
Bvibir = vibir
|
||||
BV = v
|
||||
Bvibir = vibir
|
||||
|
||||
return BV, Bvibir
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user