CF235 Let & amp; #39; s Play Osu! [Dp + probability]

Source: Internet
Author: User

CF235 Let & #39; s Play Osu! [Dp + probability]

Question:

For n positions, the probability pi of O occurrence at each position on 1-n is given. The scoring rules are as follows. x consecutive OSS records are x ^ 2 points, and the sum is calculated. For example, xxoooxooxx scores are as follows:

Expected score



<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + y7y/vNK7z8KjrM7Sw8fE3LHIvc/authorization + signature + CjxwPsTHw7Q8L3A + cjxwpjxpbwcgc3jjjpq = "http://www.2cto.com/uploadfile/Collfiles/20140824/20140824090454221.png" alt = "\">

Obviously, this question


Consider how to change the score

We have


Then the scoring method becomes

Number of consecutive O pairs × 2 + O

One O can contribute 2 points


Now the score source is changed to two places

A pair of O (2 points) and a single O (1 point)


We know

Expectation = probability x benefit

We find the probability of each pair of O × 2

Find the probability of occurrence of a single O X

Is sum expected? Http://www.bkjia.com/kf/yidong/wp/ "target =" _ blank "class =" keylink "> WPC9wPgo8cD48YnI + c1_vcd4kpha + tttttt2ssz0ru49rxjatwvcd4kpha + PHA =" http://www.2cto.com/uploadfile/Collfiles/20140824/20140824090454225.png "alt =" \ ">

Make these probabilities equal to dp [I], that is

In this way, we have a recursive relationship.

For I + 1,


The sum of dp sum is the sum of all probabilities of occurrence of o x 2

+

Probability of a single o x 1

The expected score is obtained.


#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include using namespace std;const int NN=111111;double f[NN];double dp[NN];int main(){#ifndef ONLINE_JUDGEfreopen("/home/rainto96/in.txt","r",stdin);#endifint n;scanf("%d",&n);double sum=0;for(int i=1;i<=n;i++){//cin>>f[i];scanf("%lf",&f[i]);sum+=f[i];}double ansum=0;for(int i=2;i<=n;i++){dp[i]=(dp[i-1]+f[i-1])*f[i];ansum+=dp[i];}printf("%f\n",ansum*2.0+sum);}
    
   
  
 


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.