Description
Taro and a free child are playing a dice game. There is a long checkerboard with n squares, taro and rabbits take turns to throw a dice with M face, the dice m face is 1 to M of the number. and the probability of throwing to any side is the same. Toss it to a few steps. Just walk a few paces. There is also a rule "bounce" in the game. is when a contestant is going to go to the nth. He will step back (like flying chess into the camp).
Suppose now a chaser is in A. When he throws B:
1.a+b<n, go to section a+b,
2.a+b=n, go to nth grid, win.
3.a+b≥n, go to section (N (a+b-n)
now taro and rabbits are respectively in the X and Y lattice. The next is Taro's dice, and Taro wants to know how much he is likely to win the game.
Input
A row of four integer n,m,x,y.
Output
One decimal line indicates the probability of Tai Lung winning. (6 decimal places reserved)
Sample Input
6 1 1 Sample Output
0.541725 Data Constraint
30% of the bullying, l0≤n≤100.
100% of data. 10≤n≤2000,1≤m,x,y≤n-1
Analysis
We set Fi,j f_{i,j} to indicate the probability of taro winning in position I, rabbit in position J, Taro. We should discuss it in 4 kinds of situations.
Let's consider the situation inside the bounce range, that is, in the interval [n-m+1,n],
The probability of reaching the end in this area is the same.
If taro and rabbits were in this range, they would never get out of this range,
Because no matter how back, will not retreat to n-m this position.
So what's the probability?
I the probability of direct arrival is 1m \dfrac{1}{m}
I the probability of the second arrival should be: I first did not arrive at the probability that XJ first did not reach the probability that Xi this time arrived, namely 1mx (1−1m) 2 \dfrac{1}{m}x (1-\dfrac{1}{m}) ^2
I the probability of the third arrival should be: I the probability that the first two did not arrive before XJ twice did not reach the probability that Xi this time arrives, namely 1MX (1−1m) 4 \dfrac{1}{m}x (1-\dfrac{1}{m}) ^4
The probability of the nth arrival of I is 1mx (1−1m) 2n \dfrac{1}{m}x (1-\dfrac{1}{m}) ^{2n}
Then, the final probability of this position at I should add up the probability of each arrival, 1m+1mx (1−1m) 2+1mx (1−1m) 4+...+1mx (1−1m) 2n \dfrac{1}{m}+\dfrac{1}{m}x (1-\dfrac{1}{m }) ^2+\dfrac{1}{m}x (1-\dfrac{1}{m}) ^4+...+\dfrac{1}{m}x (1-\dfrac{1}{m}) ^{2n}
Will