Allergy Testing (Small)
Time limit5sMemory limit512 MB
Kelly plans pooled food tests with different waits after negative and positive results to find her single allergy trigger in the fewest worst-case days.
- Level
Medium7 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Kelly is allergic to exactly one of foods, but she does not know which one. She decides to run experiments to find out.
In each experiment Kelly picks several foods and eats them all at once. days later she learns whether she had an allergic reaction. If there was no reaction, none of the foods she just ate is the one she is allergic to. If there was a reaction, she learns at that same moment that the food she is allergic to is among the ones she just ate, but she has to wait for the reaction to go away, so the next experiment can only start days after she ate. With no reaction, the next experiment starts right after those days.
Kelly picks the foods for each experiment based on the results of the earlier ones. She wants the worst-case number of days needed to pin down the food she is allergic to to be as small as possible. How many days is that?
Input
The first line gives the number of test cases . test cases follow. Each test case is one line holding the space-separated integers , and .
Limits
Output
For each test case, print one line in the form "Case #x: y", where is the test case number starting from 1 and is the worst-case number of days Kelly needs to find the food she is allergic to.
Explanation
For , and the answer is 12 days.
- Kelly first eats foods 1 and 2.
- If there is no reaction after 5 days, she eats food 3. Five days after that she knows whether food 3 or food 4 is the one.
- If the first experiment does give a reaction, she eats food 1 seven days after the first experiment. Five days after that she knows whether food 1 or food 2 is the one.