Test Passing Probability (Large Input)
Time limit5sMemory limit512 MB
With M submissions allowed and independent per-question probabilities, choose answers to maximize the chance that one submission is fully correct.
- Level
Hard8 of 10
- Topics
- Probability, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Dave is taking a multiple choice test online. He may submit his answers several times, but he passes only if one of his submissions has every question right. Every submission must carry an answer to every question, and the only thing he learns after a submission is whether he passed.
For each question Dave has estimated the probability that each of the four responses is the correct one. Those probabilities are independent of what he writes on the other questions. Given how many submissions he is allowed, Dave picks his answers so that the probability of passing is as large as possible.
Find the probability that Dave passes when he picks his answers optimally.
Input
The first line contains the number of test cases . test cases follow.
The first line of each test case contains the number of submissions that Dave may make and the number of questions on the test. lines follow, and each of them gives, in order, the four probabilities of correctness for one question. Every probability is at least 0 and has at most six digits after the decimal point, and the four probabilities on one line sum to 1.
Constraints
Output
For each test case, print one line holding Case #X: Y. is the number of the test case, starting from 1. is the largest passing probability, rounded to six digits after the decimal point and always printed with all six digits. A probability of exactly is printed as 0.500000.