Sam only has 100 $1 coins, 50 $2 coins, 20 $5 coins and 10 $10 coins. He needs to buy a present but he doesn't know the price. What he knows is that the price is a whole number from $1 to $100. What is the least number of coins he must bring so that he can buy the present without a change?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The trick to paying the least number of coins for a natural number payment p is to pay with the higher value coins first. For example, if p = $ 5 7 , we pay with ( ⌊ $ 1 0 $ 5 7 ⌋ = ) 5 × $ 1 0 coins first. The remainder $ 7 , we pay with ( ⌊ $ 5 $ 7 ⌋ = ) 1 × $ 5 coin first and then the remainder with 1 × $ 2 coin. Or p = $ 5 7 = 5 ( $ 1 0 ) + 1 ( $ 5 ) + 1 ( $ 2 ) . Any other ways of paying for $ 5 7 will require more coins.
Now define the combination of coins for the least number of coins to be c ( n $ 1 0 , n $ 5 , n $ 2 , n $ 1 ) , for example c ( $ 5 7 ) = ( 5 , 1 , 1 , 0 ) . With this in mind, it is obvious that:
c ( $ 1 ) = ( 0 , 0 , 0 , 1 ) c ( $ 2 ) = ( 0 , 0 , 1 , 0 ) c ( $ 3 ) = ( 0 , 0 , 1 , 1 ) c ( $ 4 ) = ( 0 , 0 , 2 , 0 ) c ( $ 5 ) = ( 0 , 1 , 0 , 0 ) c ( $ 6 ) = ( 0 , 1 , 0 , 1 ) c ( $ 7 ) = ( 0 , 1 , 1 , 0 ) c ( $ 8 ) = ( 0 , 1 , 1 , 1 ) c ( $ 9 ) = ( 0 , 1 , 2 , 0 ) ⟹ c ( $ ( 1 0 n + 1 ) ) = ( n , 0 , 0 , 1 ) ⟹ c ( $ ( 1 0 n + 2 ) ) = ( n , 0 , 1 , 0 ) ⟹ c ( $ ( 1 0 n + 3 ) ) = ( n , 0 , 1 , 1 ) ⟹ c ( $ ( 1 0 n + 4 ) ) = ( n , 0 , 2 , 0 ) ⟹ c ( $ ( 1 0 n + 5 ) ) = ( n , 1 , 0 , 0 ) ⟹ c ( $ ( 1 0 n + 6 ) ) = ( n , 1 , 0 , 1 ) ⟹ c ( $ ( 1 0 n + 7 ) ) = ( n , 1 , 1 , 0 ) ⟹ c ( $ ( 1 0 n + 8 ) ) = ( n , 1 , 1 , 1 ) ⟹ c ( $ ( 1 0 n + 9 ) ) = ( n , 1 , 2 , 0 ) where n ∈ N
And c ( $ 1 0 n ) = ( n , 0 , 0 , 0 ) . To pay for $ 1 to $ 9 9 , we need ( max ( n $ 1 0 ) = ) 9 × $ 1 0 coins, ( max ( n $ 5 ) = ) 1 × $ 5 coin, ( max ( n $ 2 ) = ) 2 × $ 2 coins, and ( max ( n $ 1 ) = ) 1 × $ 1 coin. But when we add up 9 ( $ 1 0 ) + 1 ( $ 5 ) + 2 ( $ 2 ) + 1 ( $ 1 ) = $ 1 0 0 . Therefore, to pay for $ 1 to $ 1 0 0 without a change we only need 1 3 coins, nine $ 1 0 , one $ 5 , two $ 2 , and $ 1 .