[Dp] expectations - Los Valley P1654 OSU!

Topic Portal:

At first glance, I do not understand the meaning of problems.

It is actually a very interesting topic dp expectations.

Reference for a moment to answer the big one explanation: Go


 

Set a [i] denotes the i-th bit position i before a desired length.

 

Easy to know:

a[i] = (a[i-1]+1) * p[i].

We demand that the three items, according to the desired properties can be used to expand the cubic equation and obtain a quadratic and linear terms.

The secondary set a [i] is expressed as b [i], there b [i] = a [i] ^ 2

b[i] = (a[i-1]+1)^2 = (a[i-1]^2) + 2*a[i-1] + 1

     = b[i-1]^2 + 2*a[i-1] + 1.

  You can also get three items, but the light Cubic item does not make sense, because we are asking for is n expectations, so just a bit to the case 1, but had to count a bit to 0, this but also by the situation in front of a 0 and 1 together to get, in the end we still claim that each bit is 0 the situation.

  So a change of thinking, from the outset, seeking answers:

For three terms f [i]:

f [i] = (f [i-1] + 3 * a [i-1] + 3 * b [i-1] + 1) * p [i] (i-th position currency and 1)

   + F [i-1] * (1 - p [i]) (i-th bit is not 1)

   = f[i-1] + (3*a[i-1] + 3*b[i-1] + 1) * p[i]

 

The answer to the final output!

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+10;
 4 int n;
 5 double p[N];
 6 double a[N],b[N],dp[N];
 7 int main(){
 8     scanf("%d",&n);
 9     for(int i=1;i<=n;i++){
10         scanf("%lf",&p[i]);
11     }
12     for(int i=1;i<=n;i++){
13         a[i]=(a[i-1]+1)*p[i];
14         b[i]=(b[i-1]+2*a[i-1]+1)*p[i];
15         dp[i]=dp[i-1]+(3*a[i-1]+3*b[i-1]+1)*p[i];
16     }
17     printf("%.1lf",dp[n]);
18     return 0;
19 }

 

So it is very important mathematical ideas! 

Guess you like

Origin www.cnblogs.com/Nelson992770019/p/11537374.html