No.65 Practice of Expected Number of Times
タグ : / 解いたユーザー数 370
作問者 :
nmnmnmnmnmnmnm
Problem Statement
You want to roll one die some number of times to make the sum of the rolled values at least \(K\).
Find the expected number of times the die is rolled.
For this die, it is known that the formula for the expected number of rolls \(E(x)\) is as follows.
\(E(x)\) := the expected number of further rolls needed until the sum reaches \(K\), when the sum of the values so far is \(x\)
\( E(x)=E(x+1)*1/6+E(x+2)*1/6+E(x+3)*1/6+E(x+4)*1/6+E(x+5)*1/6+E(x+6)*1/6+1\)
Input
K
K is a positive integer. \(1\le K \le 20 \).
Output
Output the expected value on one line. An absolute or relative error of up to 0.01 is allowed.
Do not forget the newline at the end.
Sample
Sample 1
Input
1
Output
1
When x>=1, E(x)=0, and when x=0, E(0)=1.
Rolling the die once can be expected to make the sum of the values at least 1.
Sample 2
Input
2
Output
1.16667
Sample 3
Input
3
Output
1.36111
Sample 4
Input
7
Output
2.52163
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。