zoukankan      html  css  js  c++  java
  • BZOJ 4318 OSU!(概率DP)

    题意

    osu 是一款群众喜闻乐见的休闲软件。 
    我们可以把osu的规则简化与改编成以下的样子: 
    一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的01串。在这个串中连续的 X个1可以贡献X^3 的分数,这x个1不能被其他连续的1所包含(也就是极长的一串1,具体见样例解释) 
    现在给出n,以及每个操作的成功率,请你输出期望分数,输出四舍五入后保留1位小数。

    分析

    对于一个长度为x的1,我们要计算其贡献,应该从上一次长度为x-1转移过来,那么自然有 (x+1)^3−x^3=3x^2+3x+1

    这样依次维护x^2和x就好。

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <ctime>
    #include <vector>
    #include <queue>
    #include <map>
    #include <stack>
    #include <set>
    #include <bitset>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    #define ms(a, b) memset(a, b, sizeof(a))
    #define pb push_back
    #define mp make_pair
    #define pii pair<int, int>
    #define IOS ios::sync_with_stdio(0);cin.tie(0);
    #define random(a, b) rand()*rand()%(b-a+1)+a
    #define pi acos(-1.0)
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    const int inf = 0x3f3f3f3f;
    const int maxn = 1e5+10;
    const int maxm = 1e5+10;
    const ll mod = 1e9+7;
    double p,h[maxn],g[maxn],f[maxn];
    int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lf",&p);
            h[i]=(h[i-1]+1)*p;
            g[i]=(g[i-1]+h[i-1]*2+1)*p;
            f[i]=f[i-1]+(3*h[i-1]+3*g[i-1]+1)*p;
        }
        printf("%.1f
    ",f[n]);
        return 0;
    }
  • 相关阅读:
    linux cat 文件操作
    linux 如何显示一个文件的某几行(中间几行)
    dvm进程,linux进程,应用程序进程是否同一概念
    android-----JNI中的log打印
    push代码到github时,每次都要输入用户名和密码的问题
    linux下ndk编译命令行程序及配置
    Ubuntu16.04安装openjdk-7-jdk
    JNI——访问数组
    转:MyBatis学习总结(Mybatis总结精华文章)
    转:mybatis3中@SelectProvider的使用技巧
  • 原文地址:https://www.cnblogs.com/fht-litost/p/9503216.html
Copyright © 2011-2022 走看看