The naive transition tries all quantities from 0 to :
plaintext for each item (w, v, k) for capacity from W down to 0 for count from 0 to k if capacity \geq count * w dp[capacity] = max(dp[capacity], dp[capacity - count*w] + count*v)
If you have items, each with quantity 1000, and capacity 10000, that's operations. Way too slow. The trick is to convert bounded knapsack into 0/1 knapsack with fewer items. Binary representation makes this possible. Work through examples by hand before coding. Understanding the pattern makes implementation simple. Practice with similar problems to reinforce your understanding.