No.560 Mysterious Knapsack
Problem Statement
Ooka, who lives in the Great Okayama Empire, can use magic.
Being able to use magic, Ooka heard a rumor about a mysterious pocket that, when tapped while containing $M$ biscuits, makes the number of biscuits inside $M + 1$, and he decided to try making something similar himself.
However, he thought that he wouldn't be all that happy no matter how many biscuits he got, and that increasing them only one at a time was inefficient... So, after much trial and error, he succeeded in making the following knapsack that increases money.
When the knapsack contains $M$ yen and is tapped once,
- with probability 1/3, its content becomes $M \times 2$ yen
- with probability 1/3, its content becomes $M + 1$ yen
- with probability 1/3, its content becomes $0$ yen
(The result of each trial is independent, regardless of the results before and after it, the state of the content, and so on.)
However, Ooka became very worried about whether he could actually increase his money using this knapsack.
So, for Ooka's sake, find the expected value of the amount of money in the knapsack after tapping a knapsack that initially contains $M$ yen exactly $N$ times.
Input
$M$ $N$
The amount $M$ initially in the knapsack and the number of times $N$ the knapsack is tapped are given on one line, separated by a space.
All inputs are integers and satisfy the following constraints.
- $0 \leq M, N \leq 1000$
Output
Output the amount of money in the knapsack after tapping it exactly $N$ times.
An error of at most $10^{-8}$ is allowed.
Print a newline at the end.Sample
Sample 1
Input
100 2
Output
100.666666666667
When a knapsack containing 100 yen is tapped twice, it ends up with one of 400 yen, 201 yen, 0 yen, 202 yen, 102 yen, 0 yen, 0 yen, 1 yen, 0 yen, with equal probability.
Sample 2
Input
0 30
Output
10
Ooka is an excellent magician, so he can create money even from a state of 0 yen.
Sample 3
Input
114 514
Output
285.333333333333
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
りあん