Knapsack problem/Bounded: Difference between revisions

Content added Content deleted
(Added 11l)
Line 116: Line 116:
R (0, best_list)
R (0, best_list)
V k = (weight, idx)
V k = (weight, idx)
I k C :cache
V? c = :cache.find(k)
R :cache[k]
I c != N
R c
V name = :item_keys[idx]
V name = :item_keys[idx]
V (w, v, qty) = :items[name]
V (w, v, qty) = :items[name]
Line 139: Line 140:
I cnt > 0
I cnt > 0
print(cnt‘ ’name)
print(cnt‘ ’name)
w = w + items[name][0] * cnt
w += items[name][0] * cnt


print(‘Total weight: ’w‘ Value: ’v)</lang>
print(‘Total weight: ’w‘ Value: ’v)</lang>