Study Questions 16-1
First of all, the coin change problem has the best sub-structure, we have to find the optimal solution of the problem of n n cents, and know that the optimal solution uses a C-penny coin, set the optimal solution using K K coins, we think the best solution to solve this problem is to use the problem n−c n-c cents and used k−1 k-1 A coin. Obviously, solving n−c n-c cents and using k−1 k-1 coins using n-N cents of the solution, if we have less than k−1 k-1 a coin to find n−c n-c cents problem, then we can use this solution instead of n-N cents problem, and less than K K coins, which with the most Excellent solution contradiction.
a) Q=⌊n/25⌋q = \lfloor n/25\rfloor, remaining n′=n mod n ' = n\ mod\ 25 cents, D=⌊n′/10⌋d=\lfloor n '/10\rfloor, remaining D′=n′mod 10,k=d′ /5 d ' =n ' \mod\ 10,k=d '/5, the remaining K′=d′mod 5 K ' =d ' \ mod\ 5, the rest are all 1 1 cents coins, the summary is to choose the largest change each time, if the denomination is larger than the selected banknotes, you can redeem, otherwise choose smaller change, and so on.
b) prove slightly.
c) There are now 30 30 cents, the denomination of the coin is 25,10,1 25,10,1, the solution obtained by the greedy algorithm is 25,1,1,1,1,1 25,1,1,1,1,1, that is, 6 6 coins, which should actually be