Crushing blow
Time limit2sMemory limit256 MB
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 , , and , where is the number of dice, is the number of faces on each die, and is a modifier. For example, if , , , 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 .
To finish the monster, a weapon must deal damage of 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 to written on it.
Input
The first line of the input file contains a single integer , the number of tests (). The descriptions of tests follow.
The first line of a test contains two integers: , the number of the character's weapons, and , the minimum damage needed to finish the monster (, ).
The next lines describe the weapons. Each line contains three integers: , the number of dice, , the number of faces on each die, and , the modifier (, , ).
The total number of weapons over all tests does not exceed .
Output
For each test, print on a separate line a single real number: the maximum probability of dealing damage of at least with one blow. The absolute error of the answers must not exceed .