You are given coin values and a sum . How many ways can you choose the coins so that they sum up to and so that the number of coins is the smallest possible?
You may assume that and that . One of the coin values is always . The algorithm should be efficient in all these cases.
In a file minways.py
, implement a function count
that returns the desired count.
def count(x, coins): # TODO if __name__ == "__main__": print(count(5, [1])) # 1 print(count(5, [1, 2, 3, 4])) # 4 print(count(13, [1, 2, 5])) # 12 print(count(42, [1, 5, 6, 17])) # 30
Explanation: When and the coin values are , there are different ways: , , and .