Fork

아직 제출이 없습니다시간 제한0.15초메모리 제한1024 MB

문제

Luca opened a Python shell and typed os.fork(), which spawned a second shell. After that, each time Luca pressed any key, it would randomly go to one of the two shells. Each shell has an input string (shown in the terminal), which is edited by the key presses going to that shell. Additionally, Luca sees the terminal and thus he knows which shell's input string was affected when he presses a key.

His keyboard has NN keys with distinct characters on them and Backspace. When a character key press goes to a shell, the character is simply appended to the end of its input string. When a Backspace key press goes to a shell, the last character of its input string is erased. If the shell's input string is empty, nothing happens to it (though Luca still sees the Backspace went there). Each key press has probability PP of going to the left shell and probability 1P1 - P of going to the right one.

Luca wants to type some fixed string a_1a_2a_Na\_1a\_2 \cdots a\_N consisting of NN distinct characters in both shells. He has already managed to type LL correct characters to the left shell and RR to the right one (i.e. the strings in the two shells are a_1a_2a_La\_1a\_2 \cdots a\_L and a_1a_2a_Ra\_1a\_2 \cdots a\_R). For example, consider P=0.3P = 0.3, N=2N = 2 (the string could be ab), L=0L = 0 and R=1R = 1. A possible sequence of events is:

StepKeySideLeft shellRight shell
0a
1bRightab
2aRightaba
3aLeftaaba
4bRightaabab
5BackspaceRightaaba
6BackspaceLeftaba
7BackspaceLeftaba
8BackspaceRightab
9aLeftaab
10bRightaabb
11bLeftababb
12BackspaceRightabab

In total, typing ab to both shells took 1212 key presses.

Let us define an incorrect character like so: a character in one of the two shells, which needs to be deleted at some point before typing the full string (and only that) to both shells. Luca has decided that he will never press Backspace, if there is no incorrect character in at least one of the shells. He has also decided that he will never press a key which will always result in an incorrect character. Luca is wondering what his optimal strategy would be under these constraints. In particular, he wants to know what is the minimum expected (average) number of key presses. Help Luca by writing a program fork.cpp which solves this problem.

입력

From the first and only line of the standard input, your program should read PP, NN, LL and RR.

출력

On the first and only line of the standard output, your program should print the computed answer to (preferably) 1212 digits of precision or more. You can use:

std::cout << std::setprecision(12) << ans << std::endl;

제한

  • 0L,RN2×1070 ≤ L, R ≤ N ≤ 2 \times 10^7
  • 0.1P0.90.1 ≤ P ≤ 0.9