fix
This commit is contained in:
parent
2c5223f97a
commit
adcd3a3d0a
17
u11/knapsack.py
Normal file
17
u11/knapsack.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
def maximum_value(maximum_weight, items):
|
||||||
|
if not items or maximum_weight <= 0:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
sorteditem = sorted(items, key=lambda x: x["value"] / x["weight"], reverse=True)
|
||||||
|
|
||||||
|
TEPvalue = 0
|
||||||
|
currweight = 0
|
||||||
|
for item in sorteditem:
|
||||||
|
if currweight + item["weight"] <= maximum_weight:
|
||||||
|
currweight += item["weight"]
|
||||||
|
TEPvalue += item["value"]
|
||||||
|
return TEPvalue
|
||||||
|
|
||||||
|
def maximum_value_with_items(maximum_weight, items):
|
||||||
|
return 0, []
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user