P26696 [AtCoder] JOI 2006 Preliminary Problem 5
提高+
题目描述

Problem Description

Consider the following game. There are $k$ sets of $n$ cards each, with numbers from $1$ to $n$ written on them. These $kn$ cards are thoroughly shuffled and then divided into $n$ piles of $k$ cards each, arranged in a row. The pile consisting of $k$ cards from left to right is referred to as "pile $i$".

2006-yo-t5-fig_base.png

The game starts with pile $1$. The top card of the pile is drawn (the drawn card is not returned to the pile), and if the number written on the card is $i$, the top card of pile $i$ is drawn. This process is repeated, drawing the top card of the pile corresponding to the number written on the drawn card, until all cards from all piles are drawn, which constitutes a success. If there are still cards left in some piles but the next pile to draw from does not exist, it is a failure.

If a failure occurs, the game can either end as a failure or restart with the remaining piles (keeping their original order). If the game restarts, the first card drawn is from the leftmost pile that still has cards (the top card of that pile). The game proceeds in the same manner as before, and a success is achieved if all cards are drawn from all piles, while a failure occurs if there are still cards left in some piles but the next pile to draw from does not exist.

The game can be restarted up to a maximum of $m$ times, where $m$ is either $0$ or $1$. That is, the game can either not be restarted or can be restarted only once. Due to the shuffling, the initial configuration of the cards varies. Depending on the initial configuration, the game may succeed without restarting, succeed after restarting, or fail even after restarting. Since the shuffling is thorough, we assume that all initial configurations appear with equal probability. We want to calculate the probability $p$ that the game succeeds within $m$ restarts, expressed as a decimal, and output it up to $r$ decimal places, satisfying the following conditions:

If there exists a sufficiently large positive integer $K$ such that $p \times 10^K$ is an integer, the decimal part should include trailing zeros. For example, if $p = 3/8 = 0.375$, for $r = 5$ output $0.37500$, and for $r = 2$ output $0.37$. Even if $p = 1.0$, for example, for $r = 3$ output $1.000$. For example, $0.150000\cdots$ can also be represented as the recurring decimal $0.1499999\cdots$, but in such cases, use the former representation. The first line of input contains the integers $n, k, m, r$ in this order, separated by spaces. $1 \leq n \leq 10,000$, $1 \leq k \leq 100$, $m = 0$ or $m = 1$, $1 \leq r \leq 10,000$.

Output should include a newline after the specified output of $p$.


Input Format

None

Output Format

None

Sample Input and Output

Sample Input #1

2 1 0 5

Sample Output #1

0.50000

Sample Input #2

3 1 1 3

Sample Output #2

0.833

Sample Input #3

2 2 1 3

Sample Output #3

1.000

Notes/Hints

Sample Explanation 1

- - - - - -

Sample Explanation 2

- - - - - -

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 1 0 5
样例输出
0.50000