The coin change problem is a standard first example of dynamic programming. It reads as follows.
- To make change for C won with coins of denominations P1,P2,…,PN, what is the smallest number of coins needed?
Byeongchan wants to solve it with a simple method. His method is as follows.
- At each step, add one coin of the largest denomination that does not exceed the amount still missing. Repeat until the remaining amount is 0.
Byeongchan's method is not always optimal. To make 8 won from coins of 1, 4, and 6, his method uses one 6 and two 1s, three coins in total. Two 4s do it with two coins.
Byeongchan realized that his method works for some sets of denominations and fails for others. Given the denominations, write a program that decides whether his method produces the smallest number of coins for every C.