Knapsack problem/Bounded: Difference between revisions

m
Tidied up repaired python non-zero-one solution. Sorry, should have done this in a single edit!
(Made repaired python non-zero-one solution slightly more readable)
m (Tidied up repaired python non-zero-one solution. Sorry, should have done this in a single edit!)
Line 3,400:
}
 
keysitem_keys = list(items.keys())
 
#cache: could just use memoize module, but explicit caching is clearer
Line 3,409:
if k in cache: return cache[k]
name, w, v, qty = keysitem_keys[idx], *items[keysitem_keys[idx]]
best_v, best_list = 0, []
Line 3,431:
if cnt > 0:
print(cnt, name)
w = w + items[keys[keys.index(name)]][0] * cnt
print("Total weight:", w, "Value:", v)</lang>
Anonymous user