This page is still under construction.

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

Orange Bowl

Time limit1sMemory limit128 MB

Summary
Given plays with a yard gain and success probability, choose a sequence whose total gain reaches n yards while maximizing the product of probabilities.
Level

Medium6 of 10

Topics
Dynamic programming, Math, Probability, Greedy
Solved
No attempts yet

Problem

It is late in the Orange Bowl football game, and USC is trailing by 4 points, desperately needing one more touchdown. So the coach reaches for his newest weapon: a play-strategy evaluator written at a programming contest.

Football is complicated, but we simplify it as follows. USC is currently nn yards away from the end zone (1≤n≤1001 \le n \le 100). The coach must choose a sequence of plays to move the ball into the end zone as safely as possible. For each play, the coach may pick from mm available plays (1≤m≤10001 \le m \le 1000). Each play ii is described by two numbers: a yard gain gig_i (an integer with 1≤gi≤1001 \le g_i \le 100) and a success probability pip_i (a real number with 0≤pi≤10 \le p_i \le 1). The play succeeds with probability pip_i; if it succeeds, it moves USC gig_i yards closer to the end zone, and if it fails, the ball is turned over and USC loses.

Choose a sequence of plays (repetitions allowed) whose total yard gain is at least nn and whose overall success probability is maximized. All plays succeed independently, so the success probability of a sequence is the product of the individual probabilities.

(An aside from the original contest: "Like USC would ever be trailing in a football game.")

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. Then follow KK data sets, each of the following form.

The first line of a data set contains nn and mm. This is followed by mm lines; the ii-th of them contains gig_i and pip_i for play ii.

Output

For each data set, first print a line "Data Set x:", where x is the data set's number (starting from 1). Then, on its own line, print the overall success probability of the play sequence most likely to reach the end zone, rounded to two decimals. You do not need to print the actual sequence.

Examples3

  1. Example 1

    Input
    2
    3 1
    1 0.7
    5 3
    1 0.94
    2 0.9
    3 0.8
    
    Expected output
    Data Set 1:
    0.34
    Data Set 2:
    0.76
    
  2. Example 2

    Input
    1
    1 1
    1 0.5
    
    Expected output
    Data Set 1:
    0.50
    
  3. Example 3

    Input
    1
    10 1
    5 1
    
    Expected output
    Data Set 1:
    1.00