This page is still under construction.

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

Horn Blowing

Time limit2sMemory limit256 MB

Summary
Compute the probability that the summed start-up delays of N vehicles with given discrete distributions total at most T seconds.
Level

Medium4 of 10

Topics
Dynamic programming, Probability
Solved
No attempts yet

Problem

People say the shortest measurable stretch of time is the gap between the light turning green and the driver behind you leaning on the horn. Yraglac is more patient than that. He honks only when the cars ahead of him take longer than a reasonable time to start moving.

His horn has three uses left before it wears out, and he refuses to buy a new one, so he waits and occupies himself with something else. He estimates the probability that he can start moving within TT seconds of the light turning green.

There are NN vehicles in front of Yraglac. Each vehicle starts moving a whole number of seconds after the vehicle directly in front of it starts moving, and that number follows the distribution given for the vehicle. The vehicle at the head of the line counts from the moment the light turns green. Yraglac starts moving at the moment the vehicle directly in front of him starts moving.

Given the distribution of every vehicle ahead of him, compute the probability that Yraglac starts moving within TT seconds of the light turning green.

Input

The input contains several test cases.

The first line of each test case has the number of vehicles in front of Yraglac, NN (0<N<10000 < N < 1000).

The next NN lines describe one vehicle each in the form k p1 p2 … pkk\ p_1\ p_2\ \dots\ p_k (0<k<100 < k < 10). Here pip_i is the probability that this vehicle starts moving ii seconds after the vehicle in front of it starts moving, with 0≤pi≤10 \le p_i \le 1 and p1+p2+⋯+pk=1p_1 + p_2 + \dots + p_k = 1. A probability may be written without its integer part, as in .5.

The line after that has the integer TT (0≤T≤100000 \le T \le 10000).

The input ends with a line containing a single 0. The sum of NN over all test cases is at most 3000.

Output

For each test case, print on one line the probability that Yraglac starts moving within TT seconds of the light turning green, truncated to two decimal places.

Truncate, do not round: 0.519 prints as 0.51. A value that is exactly 0.51 must still print as 0.51, so watch out for floating point error.

Examples2

  1. Example 1

    Input
    1
    1 1
    1
    1
    2 .5 .5
    1
    2
    2 .5 .5
    2 .25 .75
    2
    0
    
    Expected output
    1.00
    0.50
    0.12
    
  2. Example 2

    Input
    1
    1 1
    0
    2
    1 1
    1 1
    1
    2
    1 1
    1 1
    2
    1
    2 .5 .5
    5
    0
    
    Expected output
    0.00
    0.00
    1.00
    1.00