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;
    } 
  • 相关阅读:
    AngularJs $http.post 数据后台获取不到数据问题 的解决过程
    网络安全学习和CTF必不可少的一些网站
    汇编语言学习资料汇总
    链表的归并排序
    数学常用模板——矩阵 高精度
    Gym100810J Journey to the "The World's Start" (二分答案+动态规划)
    图论:最短路
    Codeforces Round #642 (Div. 3)补题
    离散数学真值表的计算
    【C/C++】字典树
  • 原文地址:https://www.cnblogs.com/Zars19/p/6917987.html
Copyright © 2011-2022 走看看