Allergy Testing (Large)
Time limit90sMemory limit512 MB
Find the shortest worst-case schedule of pooled food tests with asymmetric wait times that identifies the single allergen.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Binary search, Math
- Solved
- No attempts yet
Problem
Kelly is allergic to exactly one of foods, but she does not know which one, so she runs experiments to find out.
In one experiment Kelly picks a set of foods and eats all of them. Exactly days later she learns whether she reacted. If she did not react, she is not allergic to any food in that set. If she did react, the food she is allergic to is one of the foods in that set, and the reaction takes days to fade, counted from the moment she ate.
Kelly starts an experiment only after the previous one is completely over, so an experiment that causes no reaction occupies days and an experiment that causes a reaction occupies days. She picks the foods for each experiment after seeing the results of all earlier experiments.
The answer is the number of days until Kelly knows which food she is allergic to. Because a result arrives days after she eats, she never has to wait for the reaction of her last experiment to fade.
Kelly plays so that the worst case is as short as possible. How many days does she need in the worst case?
Input
The first line contains the number of test cases . Each of the next lines contains three space separated integers , and .
Constraints
Output
For each test case, print one line containing Case #x: y, where is the test case number starting from 1 and is the number of days Kelly needs in the worst case to find out which food she is allergic to.
Hint
For , and the answer is 12.
- 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 she is allergic to food 3 or food 4, so this branch ends on day 10.
- If the first experiment does cause a reaction, she eats food 1 seven days after the first experiment started. Five days after that she knows whether it is food 1 or food 2, so this branch ends on day 12.