Jump to content

Knapsack problem/Bounded: Difference between revisions

Made repaired python non-zero-one solution slightly more readable
(The previous Python non-zero-one solution is sensitive to the order of the elements in the items list and fails if the first item in the list is not included in the bagged items (e.g. if umbrella is first item))
(Made repaired python non-zero-one solution slightly more readable)
Line 3,428:
v, lst = choose_item(400, len(items) - 1, {})
w = 0
for icnt, itemname in enumerate(lst):
if item[0]cnt > 0:
print(*itemcnt, name)
w = w + items[keys[keys.index(item[1]name)]][0] * item[0]cnt
print("Total weight:", w, "Value:", v)</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.