Under construction

Still being built. Things may change

Game Dice

Time limit1sMemory limit128 MB

Summary
Given up to 13 dice with various face counts and a target total, compute the probability of rolling exactly that sum, to five decimals.
Level

Medium5 of 10

Topics
Dynamic programming, Probability, Math
Solved
No attempts yet

Problem

In tabletop role-playing games, players roll multi-sided dice to generate random numbers that decide the outcome of their actions. These dice come in many shapes, from a 4-sided tetrahedron to a 20-sided icosahedron. The faces of an nn-sided die, written dndn for short, are numbered from 11 to nn, and every face is equally likely to appear. The dice available in this problem are d4d4, d6d6, d8d8, d10d10, d12d12, and d20d20.

To generate a value within a desired range, it is often useful to roll several dice together and add up the numbers shown on their faces. Different combinations of dice can cover the same range, yet the probability of each total within that range can be completely different. For example, a d6d6 and a d10d10 cover the totals from 22 to 1616 inclusive, and so do two d8d8, but the probability of rolling a 99 is not the same in the two cases.

Given a set of dice and a target number, determine the probability of rolling that exact total.

Input

The input contains several test cases, one per line. Each line begins with an integer dd (1≤d≤131 \le d \le 13), the number of dice rolled. It is followed by dd dice descriptors, each one of d4d4, d6d6, d8d8, d10d10, d12d12, or d20d20. The last value on the line is an integer xx (0≤x≤10000 \le x \le 1000), the target total whose rolling probability you must compute. A single line containing 00 marks the end of the input and must not be processed.

Output

For each test case, print on its own line the probability of rolling the total xx with the given dice, rounded to exactly five decimal places. Always print all five digits after the decimal point, including trailing zeros.

Examples4

  1. Example 1

    Input
    1 d10 5
    2 d6 d6 1
    2 d10 d6 9
    2 d8 d8 9
    0
    
    Expected output
    0.10000
    0.00000
    0.10000
    0.12500
    
  2. Example 2

    Input
    1 d4 1
    1 d20 20
    1 d6 7
    0
    
    Expected output
    0.25000
    0.05000
    0.00000
    
  3. Example 3

    Input
    2 d6 d6 7
    0
    
    Expected output
    0.16667
    
  4. Example 4

    Input
    1 d12 6
    2 d20 d20 21
    0
    
    Expected output
    0.08333
    0.05000