This page is still under construction.

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

Crushing blow

Time limit2sMemory limit256 MB

Summary
For each weapon (n dice with f faces plus modifier m), compute the probability that one roll reaches damage D, and print the best probability over all weapons.
Level

Medium6 of 10

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

Problem

Khodislav is playing D&D. Right now his character is fighting a monster, and Khodislav, who is for some reason very sure of his attack, wants to finish the enemy with a final crushing blow. His character has several weapons; the damage a weapon can deal is determined by rolling dice and described by three numbers nn, ff, and mm, where nn is the number of dice, ff is the number of faces on each die, and mm is a modifier. For example, if n=3n = 3, f=8f = 8, m=5m = 5, you roll three eight-faced dice, add up the results, and add five to the sum to get the damage; this is usually written as 3d8+53d8 + 5.

To finish the monster, a weapon must deal damage of DD or greater. Help Khodislav choose a weapon for his character that kills the monster with maximum probability.

Dice rolls are independent, and every face of a die is equally likely. Each face of a die has one of the numbers from 11 to ff written on it.

Input

The first line of the input file contains a single integer TT, the number of tests (1≤T≤5 0001 \le T \le 5\,000). The descriptions of TT tests follow.

The first line of a test contains two integers: WW, the number of the character's weapons, and DD, the minimum damage needed to finish the monster (1≤W≤5 0001 \le W \le 5\,000, 1≤D≤2501 \le D \le 250).

The next WW lines describe the weapons. Each line contains three integers: nn, the number of dice, ff, the number of faces on each die, and mm, the modifier (1≤n≤101 \le n \le 10, 2≤f≤202 \le f \le 20, −10≤m≤10-10 \le m \le 10).

The total number of weapons over all tests does not exceed 5 0005\,000.

Output

For each test, print on a separate line a single real number: the maximum probability of dealing damage of at least DD with one blow. The absolute error of the answers must not exceed 10−1110^{-11}.

Examples2

  1. Example 1

    Input
    2
    2 2
    1 20 -3
    2 2 0
    1 11
    1 20 -10
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    3
    1 6
    1 6 0
    1 7
    2 6 0
    1 100
    10 20 10
    
    Expected output
    0.166666666666667
    0.583333333333333
    0.799600378342187