Acdream 1113 The Arrow (probability dp)

Source: Internet
Author: User

Acdream 1113 The Arrow (probability dp)

 

Question:

The initial state is 0. Each time a dice is dropped [], if it is in x, the number of dice is y, and if x + y> n, it is still in x.

Calculate the expected number of times the dice are dropped from 0 to n.

Analysis:

This is changed from the previous one: if the number of dice is y in x, and if the number of dice is y in x + y> n, the number of dice remains in x.

Then we set dp [I] to indicate the expected number of dice to be dropped from I to n.

So

We set the possibility to stay in the same place every time x times.

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

Then the formula of dp [I] is simplified.

The Code is as follows:

#include 
 
  #include 
  
   #include 
   
    #include using namespace std;const int maxn = 1e5+10;double dp[maxn];int main(){    int t,n;    scanf(%d,&t);    while(t--){        scanf(%d,&n);        memset(dp,0,sizeof(dp));        for(int i=n-1;i>=0;i--){            int tot=0;            double tmp=0;            for(int j=1;j<=6;j++){                if(i+j>n) tot++;                else tmp+=dp[i+j]/6.0;            }            //cout<
    
     

 

 

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.