Anonymous user
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:
}
#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 =
best_v, best_list = 0, []
Line 3,431:
if cnt > 0:
print(cnt, name)
w = w + items[
print("Total weight:", w, "Value:", v)</lang>
|