← 返回 airbnb 的题目列表Minimum Purchases to Exactly Fill Layover Hours (Unlimited Experiences)
类型:online_judge
Given a positive array durations representing the lengths (in hours) of Airbnb experiences (each with exactly 1 decimal place, e.g. 2.0, 3.5) and a layover time X hours (also with 1 decimal place), you want to:
Use exactly all X hours (the sum of chosen durations must equal X).
Minimize context switching by booking the fewest total experiences (minimize the number of items selected).
You may repeat the same experience unlimited times.
If it’s impossible to sum to exactly X, you will book nothing.
Return the minimum number of purchases; return 0 if no exact combination exists.
Input
Line 1: an array durations (space-separated decimals).
Line 2: a decimal X.
Output
An integer: the minimum number of purchases; output 0 if impossible.
Constraints
1 <= len(durations) <= 30
0 < durations[i] <= 24.0
0 < X <= 100.0
durations[i] and X have exactly 1 decimal place (you can multiply all values by 10 and solve using integers).
Example
Input: durations = [3.0, 2.0], X = 7.0 Output: 3 Explanation: 2.0 + 2.0 + 3.0 = 7.0, so the minimum purchases is 3.
Example
Input
3.0 2.0
7.0
Output
3