The last chapter ended with a warning. A greedy method grabs the choice that looks best right now and never looks back, and for some problems that is exactly the wrong thing to do. Giving change is one of those problems, and it is where we start.
Picture the ticket machine at a bus counter. It gives change in tokens worth 1, 4 and 6 taka, and it has plenty of each. You are owed 8 taka. The machine follows the greedy rule: hand over the biggest token that still fits. So it gives you a 6, then a 1, then another 1, which is three tokens. But 4 + 4 is only two. The quick rule was quick and wrong.
How can the machine find the fewest tokens, not just for 8 taka but for 80 or 8,000, and be sure it is right? Trying every combination is hopeless for big amounts. Here is a better way to look at it. Whatever the best change for 8 taka is, its last token is a 1, a 4 or a 6. If the last token is a 4, then the 4 taka that remain must be paid in the best possible way too. So the best change for 8 is one token plus the smallest of best(7), best(4) and best(2). Each of those is the same question about a smaller amount, and the same small questions keep coming back from different bigger ones. So we answer the small ones first, write each answer down once, and look it up whenever it is needed again. That habit of solving the small versions first, keeping their answers and building upward is called dynamic programming.