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
Think about it. We can easily obtain the O (N ^ 2) method.
Make DP [I] The expected score of the former I
So
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
Sum is the expected score
For a certain vertex I
There are (1, I) (2, I) (3, I) (4, I )... (I-1, I) These pairs of O, each probability is from left to right concatenation, such
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 <cstdio> # include <cstring> # include <cmath> # include <iostream> # include <algorithm> using namespace STD; const int nn = 111111; double f [NN]; double DP [NN]; int main () {# ifndef online_judgefreopen ("/home/raw.96/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 );}
Cf235 let's play Osu! [DP + probability]