#P1409. Winning Probability in the Dice Queue
Winning Probability in the Dice Queue
Winning Probability in the Dice Queue
There are \(n\) persons standing in a line, and you are in the \(m\)th position. The game proceeds in rounds. In each round, the person at the front of the queue rolls a fair dice. The outcomes are as follows:
- If the dice shows \(1\) (with probability \(\frac{1}{6}\)), the person at the front wins immediately.
- If the dice shows one of \(\{2,4,6\}\) (with probability \(\frac{1}{2}\)), the person at the front goes to the end of the queue.
- If the dice shows one of \(\{3,5\}\) (with probability \(\frac{1}{3}\)), the person at the front leaves the queue.
The game continues until there is only one person remaining, who is then declared the winner. Given \(n\) and \(m\), compute the probability that you (the person initially at position \(m\)) will eventually win.
Note: All formulas are given in \(\LaTeX\) format.
inputFormat
The input consists of a single line containing two integers \(n\) and \(m\) (with \(1 \leq m \leq n\)), where \(n\) is the total number of people and \(m\) is your initial position in the queue.
outputFormat
Output a single line containing the probability that you will eventually win the game. The answer should be printed as a floating-point number with 6 digits after the decimal point.
sample
1 1
1.000000