• [Codeforces Round #146 (Div. 1) B]Let's Play Osu!(期望Dp)


    Description

    You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n characters "O" and "X".

    Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO", then there's three maximal consecutive "O"s block "OO", "OOO", "OO", so your score will be 22 + 32 + 22 = 17. If there are no correct clicks in a play then the score for the play equals to 0.

    You know that the probability to click the i-th (1 ≤ i ≤ n) click correctly is pi. In other words, the i-th character in the play sequence has pi probability to be "O", 1 - pi to be "X". You task is to calculate the expected score for your play.

    Solution

    题意:n个位置,每个位置有pi的概率点击成功,连续的x次成功将会被计分为x2,问总得分的期望

    用f[i]表示到第i个位置的期望得分,可以维护一个g[i]表示以i结尾的期望连续成功次数

    g[i]=(g[i-1]+1)*pi

    f[i]=f[i-1]*(1-pi)+(f[i-1]-g[i-1]2+(g[i-1]+1)2)*pi

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #define MAXN 100005
    using namespace std;
    int n;
    double p,f[MAXN],g[MAXN];
    int main()
    {
        while(~scanf("%d",&n))
        {
            for(int i=1;i<=n;i++)
            {
                scanf("%lf",&p);
                g[i]=(g[i-1]+1)*p;
                f[i]=f[i-1]*(1-p);
                f[i]+=(f[i-1]-g[i-1]*g[i-1]+(1+g[i-1])*(1+g[i-1]))*p;
            }
            printf("%.10lf
    ",f[n]);
        }
        return 0;
    } 
  • 相关阅读:
    js 匿名函数的链式调用
    mysql 数据库操作的一般操作命令
    js 截取一定数量的字节
    js 截取10个字节
    BootStrap入门教程 (四)
    安装Dedecms遇到的一系列问题
    BootStrap入门教程 (三)
    dedecms标签调用大全
    artDialog皮肤引入方式
    织梦cms安装完成后登录后台出现空白。主要原因是php版本的问题
  • 原文地址:https://www.cnblogs.com/Zars19/p/6917987.html
Copyright © 2020-2023  润新知