#P2001. 硬币的面值
硬币的面值
Description
Xiao A has types of coins and wants to buy an item priced at no more than yuan. He does not want to receive change (it’s dirty), and he also does not want to carry too many coins. Each denomination can be used repeatedly. Given the denominations of these types of coins, what is the minimum number of coins needed so that all prices from to can be formed exactly?
Input Format
The first line contains two integers: .
The next line contains integers, the coin denominations.
Output Format
Output a single integer: the minimum number of coins. If there is no solution, output No answer!!!.
5 31
1 2 8 4 16
5
Hint
Constraints
Only testcases 9 and 10 are designed to trip people; greedy is fine.
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号