Another Dice Game

Time limit1sMemory limit128 MB

Summary
Compute the probability that Jan reaches a target score of n in Pickomino with optimal play, given the dice, set-aside and worm rules.
Level

Hard8 of 10

Topics
Dynamic programming, Probability, Greedy, Game theory
Solved
No attempts yet

Problem

In the game Pickomino (also known in the Netherlands as Regenwormen) you must roll 8 dice to reach at least a given target score. The rules are as follows.

  • Each die shows the values 1, 2, 3, 4, 5 and a worm. The dice are fair, so every outcome is equally likely.
  • The game starts by rolling all dice.
  • After a roll, the player must pick one of the six possible values and set aside every die showing that value. At least one die must show the chosen value.
  • After setting some dice aside, the player may either roll the remaining dice again or stop. The player may only stop once at least one worm has been set aside.
  • Each value may be chosen at most once during the game.
  • When the player stops, the total score is the sum of the values of the dice that were set aside. A worm is worth 5 points.
  • The player gets stuck if any of these happen: the roll shows only values that were already set aside, all dice have been set aside without a worm, or the target score has not been reached.
  • A stuck player scores 0 points and the game ends.

Jan is playing and wants to score at least nn points. Using an optimal strategy, what is the probability that Jan reaches this target?

Input

The first line contains one positive integer: the number of test cases (at most 100).

Each of the following test cases consists of one line with the integer nn (1≤n≤401 \le n \le 40): the target score.

Output

For each test case, print one line with the probability of scoring at least nn points under an optimal strategy, rounded to exactly 10 decimal places.

Hint

To reach 5 points it is enough to roll at least one worm, so the optimal strategy is to stop as soon as you have a worm. If you did not roll a worm, you should set aside as few dice as possible to maximize the chance of rolling a worm on a later roll.

Examples5

  1. Example 1

    Input
    3
    5
    21
    40
    
    Expected output
    0.9934260979
    0.8930267372
    0.0001461079
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    0.9934260979
    
  3. Example 3

    Input
    1
    40
    
    Expected output
    0.0001461079
    
  4. Example 4

    Input
    1
    6
    
    Expected output
    0.9934247686
    
  5. Example 5

    Input
    6
    10
    15
    20
    25
    30
    35
    
    Expected output
    0.9932673272
    0.9860079561
    0.9188722841
    0.6803307112
    0.2637895195
    0.0289075054