Unbounded Knapsack
Picture a vending machine stocked with snacks. You have a budget, and you can buy any snack as many times as you want — there's no limit per item. You're trying to maximize how much you get for your money. That's Unbounded Knapsack.
Compare this to 0/1 Knapsack, where each item is unique (like packing a suitcase — you only have one jacket). Here, the supply is unlimited. That one difference completely changes the DP update direction.
The One-Direction Flip
In 0/1 Knapsack, we iterated capacity from right to left to prevent reusing an item. In Unbounded Knapsack, we want reuse — so we iterate left to right. When we compute dp[cap], dp[cap - wt[i]] has already been updated in the current pass, which means item i could have been used again. That's exactly what we want.
Recurrence: dp[cap] = max(dp[cap], dp[cap - wt[i]] + val[i]) for each item i, iterating cap from wt[i] to W.
Coin Change — Minimum Coins
Given coin denominations, what's the fewest coins to make a target amount? This is unbounded knapsack where each "item" is a coin, its "weight" is its value, and you're minimizing count instead of maximizing value. dp[amount] = min over all coins c of (dp[amount - c] + 1). Initialize dp[0] = 0, dp[w] = ∞ for w > 0.
Coin Change 2 — Count the Ways
How many distinct combinations of coins make the amount? dp[w] += dp[w - c] for each coin c. But be careful: put coins in the outer loop and amounts in the inner loop. This counts combinations (where [1,2] and [2,1] are the same thing). Flipping the loops would count permutations instead.
Rod Cutting
A rod of length n can be cut and sold in pieces. Each piece length has a price. Maximize revenue. Every cut length is a reusable "item" — this is pure unbounded knapsack. dp[l] = max over all cut lengths c of (price[c] + dp[l - c]).