Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 51s1 days 16 hours 1 minutes 51 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 51s1 days 16 hours 1 minutes 51 seconds.

Sign in to watch this lesson
Algorithms - Dynamic Programming · 4:36
Each item exists once and has a weight and a value: with items (3, 4) and (4, 5) and a bag of capacity 7, the table f[i][j] = max(f[i-1][j], f[i-1][j-w] + v) reaches 9. We squeeze it into one row and watch the loop direction decide the problem: sweeping j downward reads only the old row (0/1 knapsack), while the same line sweeping upward reads freshly updated cells and takes an item twice (unbounded knapsack). Then bounded knapsack by binary splitting (13 copies become bundles 1, 2, 4, 6; about 40 times faster than copy by copy on this Mac), exact-capacity initialisation, subset sum with bitset shifts, value-indexed tables for huge capacities, and the capital-allocation framing used in quant interviews.