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);}