Game Dice
Time limit1sMemory limit128 MB
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 -sided die, written for short, are numbered from to , and every face is equally likely to appear. The dice available in this problem are , , , , , and .
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 and a cover the totals from to inclusive, and so do two , but the probability of rolling a 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 (), the number of dice rolled. It is followed by dice descriptors, each one of , , , , , or . The last value on the line is an integer (), the target total whose rolling probability you must compute. A single line containing 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 with the given dice, rounded to exactly five decimal places. Always print all five digits after the decimal point, including trailing zeros.