The naïve polynomial expectation solution

Source: Internet
Author: User




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

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.