This page is still under construction.

Parts of this page are still being built. What you see may change.

Test Passing Probability (Large Input)

Time limit5sMemory limit512 MB

Summary
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 CC. CC test cases follow.

The first line of each test case contains the number of submissions MM that Dave may make and the number of questions QQ on the test. QQ 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

  • 1≤C≤1001 \le C \le 100
  • 1≤Q≤301 \le Q \le 30
  • 1≤M≤100001 \le M \le 10000

Output

For each test case, print one line holding Case #X: Y. XX is the number of the test case, starting from 1. YY is the largest passing probability, rounded to six digits after the decimal point and always printed with all six digits. A probability of exactly 0.50.5 is printed as 0.500000.

Examples2

  1. Example 1

    Input
    3
    10 2
    0.25 0.25 0.25 0.25
    0.25 0.25 0.25 0.25
    64 3
    0.3 0.4 0.0 0.3
    1.0 0.0 0.0 0.0
    0.2 0.2 0.2 0.4
    3 2
    0.5 0.17 0.17 0.16
    0.5 0.25 0.25 0.0
    
    Expected output
    Case #1: 0.625000
    Case #2: 1.000000
    Case #3: 0.500000
    
  2. Example 2

    Input
    2
    1 1
    0.4 0.3 0.2 0.1
    4 1
    0.4 0.3 0.2 0.1
    
    Expected output
    Case #1: 0.400000
    Case #2: 1.000000