Problem Statement | |||||||||||||
The formerly celebrated general Archibald Waving has retired after losing the fifth army. His new peaceful lifestyle made him fond of board games. A particular one is a two player game in which each player has to take a checker across a sequence of cells on the board until reaching the final cell. There are n cells in the board and they are numbered from 1 to n. The dice in use has d faces and each number between 1 and d has the same probability of being the result of a dice throw. For fun purposes, Waving may play with insanely multi-faced dices. In each turn, a player throws a dice and then moves his piece up for as many positions as the face of the dice indicates. A player wins when he reaches the cell n. Waving has been playing against his wife, Esther, who has added a new rule to the game called 'bouncing'. This rule comes into action when a player whose position is on the last cells of the board gets a dice value that is larger than necessary to reach the n-th cell. In that case, instead of winning the game, the player will bounce back to the previous cells. Formally, if a is the current cell number in which the player's checker is located and b is the result of the dice throw then the following rules are used:
Archibald has been wondering how does this rule affect the odds of winning the game at different states. You are given the number of cells n, the number of faces in the dice d, the cell on which Archibald's checker is currently located x and the cell on which Esther's checker is located y. Archibald is the next player to move. Return the probability of Archibald winning the game. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | The returned value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
- | n will be between 10 and 5000, inclusive. | ||||||||||||
- | d, x and y will be between 1 and n-1, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|