Acdream 1113 the Arrow (probability DP for expectation)

Source: Internet
Author: User

E-the ArrowTime limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld &%llu< /c7> SubmitStatus

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

Output

Each test output a number rounded to the second digit.

Sample Input

11

Sample Output

6.00

Test instructions

The initial state at 0, each drop of the dice [1,6], if now at x, the number of lost dice is Y, if X+y>n then still stay in X.

Expect the number of dice lost from 0 to N.

Analysis:

If now at x, the number of dice lost is Y, if X+y>n then still stay in X.

So we set dp[i] to indicate the desired number of dice to be lost from I to n

So

We have X-times every time we can stay where we are.

Dp[i] =dp[i]*y/6+dp[i+1]/6+dp[i+2]/6..+1;

Then simplify the formula to get Dp[i].

For a particular few, for example:

Dp[n-3] = dp[n-3]/2 + DP[N-2]/6 + DP[N-1]/6 + DP[N]/6 + 1;

That is, in the n-3 position, there is a 1/2 probability of the same, 1/6 probability plus 1, 1/6 probability plus 2,

The probability of 1/6 plus 3, the average expectation after multiplying, and the time that it is cast is the expected value of I.

The final result of this state transfer equation is dp[0].

#include <iostream>#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<math.h>#include<string.h>using namespacestd;intMain () {inti,n,t; Doubledp[101005]; CIN>>T;  while(t--) {memset (DP,0,sizeof(DP)); CIN>>N; Dp[n-1]=6; Dp[n-2]=6; Dp[n-3]=6; Dp[n-4]=6; Dp[n-5]=6; Dp[n-6]=6;  for(inti=n-7; i>=0; i--)        {             for(intj=1; j<=6; j + +) {Dp[i]+=dp[i+j]/6; } Dp[i]+=1; } printf ("%.2lf\n", dp[0]); }    return 0;}

Acdream 1113 the Arrow (probability DP for expectation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.