By the expected linearity of
can be added together
So x^3 x^2 K separate consideration
X^2 x^3 See Bzoj 4318:osu! Expected DP
Let's talk a little bit about K.
Each state can be viewed as a 01-string
For each k change must be at 0 end or 1 end
So you can offset it every time.
But of course there are exceptions.
When the first and last one is the same, it will not be able to offset
So just add that to the situation.
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read () {int x=0
, F=1;char Ch=getchar (); while (ch< ' 0 ' | |
Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}
while (ch<= ' 9 ' &&ch>= ' 0 ') {x= (x<<3) + (x<<1) +ch-' 0 '; Ch=getchar ();}
return x*f;
} int N;
Double K,p[1000010],l1[1000010],l2[1000010],n1[1000010],f[1000010][2],ans;
int main () {register int i,j;
scanf ("%d%lf", &n,&k);
for (int i=1;i<=n;i++) {scanf ("%lf", &p[i]);
l1[i]= (l1[i-1]+1) *p[i];
n1[i]= (n1[i-1]+1) * (1-p[i]);
l2[i]= (l2[i-1]+2*l1[i-1]+1) *p[i];
f[i][1]=f[i-1][1]+ (3*l2[i-1]+3*l1[i-1]+1) *p[i];
f[i][2]=f[i-1][2]-(2*n1[i-1]+1) * (1-p[i]);
} Ans+=f[n][1]+f[n][2];
ans=ans+p[1]*p[n]*k-(1-p[1]) * (1-p[n]) *k;
printf ("%lf\n", ans);
return 0; }