|
<p> |
|
<strong>"Okay, Wizard, cast your spell!"</strong> |
|
</p> |
|
|
|
<p> |
|
But which of your many spells to cast? In the ever-popular role-playing game |
|
<em>Dungeons & Dragons</em>, or <em>D&D</em>, you determine a spell's damage |
|
by rolling polyhedral |
|
dice with 4, 6, 8, 10, 12, or 20 sides. Since there's a lot of dice-rolling |
|
involved, players use shorthand to denote which dice should be rolled. |
|
<strong>X</strong>d<strong>Y</strong> means |
|
"roll a <strong>Y</strong>-sided die <strong>X</strong> times, and sum the rolls''. |
|
Sometimes, you must add or subtract a value <strong>Z</strong> after |
|
you finish rolling, in which case the notation is |
|
<strong>X</strong>d<strong>Y</strong>+<strong>Z</strong> or |
|
<strong>X</strong>d<strong>Y</strong>-<strong>Z</strong> respectively. |
|
</p> |
|
|
|
<p> |
|
For example, if you roll 2d4+1, you'll end up with a result between 3 and 9 |
|
inclusive. If you roll 1d6-3, your result will be between -2 and 3 inclusive. |
|
</p> |
|
|
|
<p> |
|
In <em>D&D</em>, wizards are powerful but flimsy spellcasters. As a wizard |
|
fighting a zombie, your best strategy is to maximize the chance that you can |
|
kill the zombie with a single spell before it has a chance to retaliate. What |
|
spell should you cast? |
|
</p> |
|
|
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of zombies |
|
you'll fight. For each zombie, there are two lines. The first contains two |
|
integers, <strong>H</strong> and <strong>S</strong>, the minimum amount of |
|
damage it takes to defeat the zombie, and the number of spells you have prepared, |
|
respectively. The second line contains <strong>S</strong> spell descriptions separated by |
|
single spaces. A spell description is simply the amount of damage a spell does |
|
in the notation described above. |
|
</p> |
|
|
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For each zombie, print a line containing the probability of defeating the zombie if you select your spell optimally. |
|
</p> |
|
|
|
<p> |
|
Absolute and relative errors of up to 1e-6 will be ignored. |
|
</p> |
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 1,000 <br /> |
|
1 ≤ <strong>H</strong> ≤ 10,000 <br /> |
|
2 ≤ <strong>S</strong> ≤ 10 <br /> |
|
</p> |
|
|
|
<p> |
|
Additionally, the following constraints will hold for each spell: |
|
</p> |
|
|
|
<p> |
|
1 ≤ <strong>X</strong> ≤ 20 <br /> |
|
<strong>Y</strong> ∈ {4, 6, 8, 10, 12, 20} <br /> |
|
1 ≤ <strong>Z</strong> ≤ 10,000, if <strong>Z</strong> is specified. <br /> |
|
<strong>X</strong>, <strong>Y</strong>, and <strong>Z</strong> |
|
will be integers with no leading zeros. <br /> |
|
</p> |
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the first case, you can guarantee a kill with the first spell, which must always do at least 2 damage. |
|
</p> |
|
|
|
<p> |
|
In the third case, your first spell is the best. If you roll a 4, you'll do the requisite 8 damage. The second spell requires |
|
rolling a 4 on two dice rather than just one, and the third spell requires rolling a 4 on all three dice. |
|
</p> |
|
|