01Where greedy breaks: coins {1, 3, 4}
Pay 6 with as few coins as possible, using coins of value 1, 3 and 4. Greedy grabs the biggest coin that fits: 4, then 1, then 1, three coins. But 3 + 3 uses only two.
Greedy failed because its first choice looked good locally and ruined the rest. DP never commits early: for every amount it remembers the best answer, and it builds bigger amounts from those.
The state is one sentence: dp[a] = the fewest coins that make exactly amount a. The base is dp[0] = 0. For any other a, the last coin you used was some c, and before it you had made a − c optimally. So
dp[a] = 1 + min over coins c ≤ a of dp[a − c]
with dp[a] = ∞ when no coin fits. Fill a = 1, 2, …, A and the answer is dp[A].