zoukankan      html  css  js  c++  java
  • [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;
    } 
  • 相关阅读:
    Qt之JSON生成与解析
    Qt的QLineEdit显示密码
    Ubuntu14.04 64位运行32位程序
    Xcode 7在支持ipad的设备中需要支持分屏!
    「模板」平衡树
    [NOI2016]区间 题解(决策单调性+线段树优化)
    [NOIP模拟测试12]题解
    [笔记乱写]0/1分数规划
    [NOIP模拟测试11] 题解
    [SCOI2014]方伯伯的玉米田 题解(树状数组优化dp)
  • 原文地址:https://www.cnblogs.com/Zars19/p/6917987.html
Copyright © 2011-2022 走看看