Bulletproof Glass Testing Budget
InterviewTime limit1sMemory limit256 MB
Compute the minimum worst-case budget to find the exact breaking distance when each bullet and each broken pane costs money.
- Level
Medium6 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Your boss thinks his life is in danger, so he had bulletproof glass fitted to his car. He doubts that the glass is really bulletproof. He fired one shot from feet away and the glass held, but he does not know whether it holds at a shorter range.
The glass has an unknown limit . A bullet fired from feet or farther cannot break it, and a bullet fired from closer than feet breaks it. The shot from feet did not break the glass, so . This is the value your boss wants.
Testing happens at whole feet only. One bullet costs . When a shot breaks the glass, replacing that pane costs another , and the replacement costs the same even if no further shot is needed. A pane that survives a shot is shot at again as it is.
Firing from feet down to feet one foot at a time settles and breaks at most one pane, so it costs at most . Breaking more glass to save bullets is sometimes cheaper.
The testing has to determine whatever position the glass breaks at. Find the smallest budget that covers the worst case.
Input
The first line has the number of test configurations ().
Each of the next lines has three integers , and separated by spaces. is the distance at which the glass is known to hold (), is the price of one pane of glass (), and is the price of one bullet ().
Output
For each test configuration print Case #n: first, then the smallest budget needed for the testing of that configuration. Here is the number of the configuration, counted from in input order.