Cutting Banknotes
Time limit1sMemory limit1024 MB
Given a target amount in cents and a set of banknote values, decide whether some subset of notes can be split into halves repeatedly so the resulting pieces sum exactly to the target.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Greedy, Bit manipulation
- Solved
- No attempts yet
Problem
Philip often faces a big problem: after going out for dinner or having a few beers, he owes money to his friends, or the other way around. These are usually small amounts, but Philip hates coins, so his wallet contains only banknotes. That means he usually cannot pay the amount exactly. Since he hates coins, he also does not allow his friends to give coins as change. He does allow banknotes as change.
To deal with this problem, he and his friends came up with an idea: pay with pieces of banknotes. To make cutting easy, they only cut a banknote into two equally sized pieces, cut those pieces into two pieces each, and so on. This gives a much larger range of amounts that can be paid. Philip wonders which amounts exactly.
Input
The first line contains an integer (1 ≤ ≤ 100): the number of test cases. Then, for each test case:
- One line with a number (0.01 ≤ ≤ 10 000.00): the amount Philip has to pay. It is formatted with two decimal digits and a period as the decimal separator.
- One line with a positive integer (1 ≤ ≤ 1 000): the number of different banknotes.
- lines, each with an integer (1 ≤ ≤ 10 000): the values of the banknotes.
Output
For each test case:
- One line with
yesif the amount can be paid exactly, andnootherwise.