c、With actual U.S. coins, we can use coins of denomination 1, 10, and 25. When
n = 30 cents, the greedy solution gives one quarter and five pennies, for a total
of six coins. The non-greedy solution of three dimes is better.
The smallest integer numbers we can use are 1, 3, and 4. When n = 6 cents, the
greedy solution gives one 4-cent coin and two 1-cent coins, for a total of three
coins. The non-greedy solution of two 3-cent coins is better.
d、Since we have optimal substructure, dynamic programming might apply. And
indeed it does.
Let us define c[ j ] to be the minimum number of coins we need to make change
for j cents. Let the coin denominations be d1, d2, . . . , dk . Since one of the
coins is a penny, there is a way to make change for any amount j ≥ 1.
Because of the optimal substructure, if we knew that an optimal solution for
the problem of making change for j cents used a coin of denomination di , we
would have c[ j ] = 1 + c[ j − di ]. As base cases, we have that c[ j ] = 0 for all
j ≤ 0.
To develop a recursive formulation, we have to check all denominations, giving
c[ j ] = 0 if j ≤ 0 ,
1 + min{c[ j − di ]} (among which , 1≤i≤k) if j > 1 .
We can compute the c[ j ] values in order of increasing j by using a table.