Kubb
Apart from Liar’s dice, another game that Simon likes is the traditional Swedish game of Kubb, also known as “Viking chess”. The exact rules of Kubb are complex, and vary from household to household. However, one aspect always remains the same, which is that of hitting the opposing team’s base line of Kubbs.
Your opponent has placed $N$ Kubbs in a line, with a constant distance between them. We can refer to the Kubbs’ positions as $1, 2, \dots , N$. Your aim is to throw batons at these to strike them down, and you want to do this with as few throws as possible.
However, your aim is not perfect. When you throw a baton at a position $x$ (which can be any integer), with probability $p_ a$ you will hit the Kubb (if any) at position $x-1$, with probability $p_ b$ you will hit the one at position $x$, and with probability $p_ c$ the one at position $x+1$. Note that it is possible to aim outside of $1 \dots N$ (for instance, at Kubb positions $0$ or $N+1$).
If you decide optimally in each step how to throw your batons, how few throws do you need on average to strike down all the Kubbs?
Input
The first line of input contains the positive integer $N$. The second line of input contains the three numbers $p_ a, p_ b, p_ c$ ($0 \le p_ a, p_ b, p_ c$, $0.1 \le p_ a + p_ b + p_ c \le 0.9$).
Output
Output a single line – the minimum expected number of throws needed to strike down all the Kubbs. The answer should have an absolute or relative error of at most $10^{-5}$.
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. To get the points for a test group you need to solve all test cases in the test group. Your final score will be the maximum score of a single submission.
|
Group |
Points |
Constraints |
|
1 |
5 |
$N = 5$, $p_ a = p_ c = 0$ |
|
2 |
10 |
$1 \le N \le 10$ |
|
3 |
15 |
$1 \le N \le 26$ |
|
4 |
20 |
$1 \le N \le 100$, $p_ b = 0$ |
|
5 |
25 |
$1 \le N \le 100$, $p_ a = p_ c$ |
| Sample Input 1 | Sample Output 1 |
|---|---|
5 0 0.5 0 |
10.000000000000000 |
| Sample Input 2 | Sample Output 2 |
|---|---|
10 0.3 0 0.4 |
18.565181174510624 |
| Sample Input 3 | Sample Output 3 |
|---|---|
11 0.14 0.2 0.16 |
33.796789761752351 |
| Sample Input 4 | Sample Output 4 |
|---|---|
25 0.1 0.2 0.3 |
52.706473580898368 |
| Sample Input 5 | Sample Output 5 |
|---|---|
100 0.145 0.21 0.145 |
292.877820791207512 |
