2168. Game Dice

单点时限: 2.0 sec

内存限制: 256 MB

In the game of Dungeons & Dragons, players often roll multi-sided dice to generate random numbers which determine the outcome of actions in the game. These dice come in various flavors and shapes, ranging from a -sided tetrahedron to a -sided isocahedron. The faces of an -sided die, called for short, are numbered from to . Ideally, it is made in such a way that the probabilities that any of its faces shows up are equal. The dice used in the game are , and .

When generating random numbers to fit certain ranges, it is sometimes necessary or desirable to roll several dice in conjunction and sum the values on their faces. However, we may notice that although different combinations of dice yield numbers in the same range, the probabilities of rolling each of the numbers within the range differ entirely. For example, a and a afford a range of to inclusive, as does two s, but the probability of rolling a differs in each circumstance.

Your task in this problem is to determine the probability of rolling a certain number, given the set of dice used.

输入格式

The input test file will contain multiple cases, with each case on a single line of input. The line begins with an integer (where ), the number of dice rolled. Following are d descriptors of dice, which can be any of “d4”, “d6”, “d8”, “d10”, “d12”, or “d20”. The last number on each line is an integer (where ), the number for which you are to determine the probability of rolling with the given set of dice. End-of-input is marked by a single line containing ; do not process this line.

输出格式

For each test case, output on a single line the probability of rolling with the dice, accurate to five decimal places. Note that even if there trailing zeros, you must show them (see Test problem for an example of decimal formatting).

样例

Input
1 d10 5
2 d6 d6 1
2 d10 d6 9
2 d8 d8 9
0
Output
0.10000
0.00000
0.10000
0.12500

4 人解决,14 人已尝试。

5 份提交通过,共有 39 份提交。

8.8 EMB 奖励。

创建: 12 年,6 月前.

修改: 2 年,2 月前.

最后提交: 2 年,2 月前.

来源: Stanford Local 2007

题目标签