← 返回 airbnb 的题目列表Coin Change Variant with Floating-Point Denominations
类型:online_judge
Coding Question
You are given coin denominations coins as decimals (e.g., 0.25, 0.5, 1.0) and a decimal target. Compute:
the minimum number of coins needed to sum to target if possible;
otherwise output -1.
Input (stdin)
Line 1: integer n, number of coin types.
Line 2: n decimal numbers coins[i] separated by spaces.
Line 3: a decimal number target.
Output (stdout)
One integer: minimum number of coins, or -1.
Constraints
1 <= n <= 30
Unlimited usage per coin
coins[i] > 0, target > 0
Inputs have at most 2 decimal places (key nuance: floating-point precision)
After scaling by 100: target_int <= 100000
Requirement
Do not use floating values as DP states. Scale to integers first, then solve standard coin change.
Examples
See the 5 test cases in the Chinese prompt.
Example
Input
3
0.25 0.5 1.0
1.5
Output
2