The ArrowTime limit:2000/1000ms (java/others)
Memory limit:128000/64000kb (java/others) problem Description
The history shows, that We need heroes in every dynasty. For example, Liangshan heroes. People hope that these heroes can punish the bad guys and recover the justice. Nowadays, we also need heroes to provent us from being chopped, or being attacked by a bomb.
Kuangbin is a very very very very very .... (very * 1e9) good boy, after he knows the arrow, he want to being the arrow of China. But he's also a little afraid of being killed by the bad guys. So he decides to throw dices to make the decision.
The dice is a cube with 1 2 3 4 5 6 on it ' s sides. When he throws a dice, every number was of the same probablity to appear. He would write down a number N in the paper at first, and then throw the dice. When the sum of the number he throwed was less than N, he would keep throwing. But if the sum is exceeds N, this throwing does not count.
For example, if the sum is 5,and N are 6, if we throw 2, 5 + 2 > 6, then the sum keeps to be 5.
If He can end the throwing in a certain time, he'll make the decision to become the Arrow.
Now, Kuangbin wonders, the expectation of the time of the throwing dices.
Input
First line, the number of cases T <=
In the next T lines, there would be T numbers.
Every number is not bigger than 100000
OutputEach test output a number rounded to the second digit.Sample Input
11
Sample Output
6.00
SourceWuyiqiManagerWuyiqi
Title Link: http://acdream.info/problem?pid=1113
The main idea: Roll the dice, if the number of points before the throw and the current throw to the point greater than n does not do processing, otherwise accumulated, to throw to the numbers n throw the expected number of times
Title analysis: First Dp[n] must be 0, push forward
Get dp[i] = Cnt/6dp[i] + 1/6dp[i-1] + 1/6dp[i-2] + ... + 1/6dp[i-6] + 1, here CNT represents the number of points before and plus the current points greater than N of the current points, simplify this recursive dp[i ] Can
#include <cstdio> #include <cstring>int const MAXN = 1e5 + 5;double dp[maxn];int main () { int T, n; scanf ("%d", &t); while (t--) { scanf ("%d", &n); memset (DP, 0, sizeof (DP)); Dp[n] = 0.0; for (int i = n-1; I >= 0; i--) { Dp[i] = 0; int cnt = 0; for (int j = 1; J <= 6; j + +) { if (i + J > N) cnt + +; else dp[i] + = Dp[i + j]; } Dp[i] + = 6; Dp[i]/= (6-cnt); } printf ("%.2f\n", Dp[0]);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Acdream 1113 the Arrow (probability DP for expectation)