Cover Up
Time limit1sMemory limit128 MB
Given per-digit candidate lists with known-candidate probabilities, compute the win probability when the contestant plays optimally.
- Level
Medium6 of 10
- Topics
- Probability, Dynamic programming, Greedy, Math
- Solved
- No attempts yet
Problem
A popular game show has a game in which a contestant guesses a multi-digit number (the price of a new car) one digit at a time. For each digit there are several numbers to choose from (say two for the first digit, three for the second, and so on), and exactly one of them is correct.
On each turn the contestant selects one number for every digit that is not yet correct, choosing only among the numbers not already picked for that digit, and is then told which selections are correct. If at least one new digit is correct this turn, the contestant may guess again for all still-incorrect digits. The contestant keeps guessing as long as every turn produces at least one new correct digit. The game ends when either all digits are correct (a win) or a turn produces no new correct digit (a loss).
For each digit, some of the choices are marked as known candidates. If a digit offers choices of which are known candidates, and the probability that the correct number is one of the known candidates is , then each known candidate is equally likely to be correct (probability each) and each of the other choices is equally likely to be correct (probability each). For example, if a digit has five choices of which two are known candidates carrying a combined chance, then each known candidate has a chance and each of the other three has a chance.
Determine the probability of winning the game when the contestant uses an optimal strategy for choosing numbers.
Input
Each test case consists of two lines. The first is , the number of digits in the number to be guessed; the maximum value of is . The second line contains triplets of the form , where is the number of choices for a digit, is the number of known candidates, and is the probability that one of the known candidates is correct. In all cases and . Whenever (there are no known candidates), is always . A line containing a single terminates the input.
Output
For each test case, output the probability of winning using an optimal strategy. All probabilities should be rounded to the nearest thousandth, and trailing zeros should not be output. (A chance of winning should be output as .)