zoukankan      html  css  js  c++  java
  • LightOJ 1248 Dice (III)

    期望,$dp$。

    设$dp[i]$表示当前已经出现过$i$个数字的期望次数。在这种状态下,如果再投一次,会出现两种可能,即出现了$i+1$个数字以及还是$i$个数字。

    因此 $dp[i]=dp[i]*i/n+dp[i+1]*(n-i)/n+1$,即$dp[i]=dp[i+1]+n/(n-i)$,$dp[n]=0$,推出$dp[0]$即可。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
    }
    
    int T,n;
    double dp[100010];
    
    int main()
    {
        scanf("%d",&T); int cas=1;
        while(T--)
        {
            scanf("%d",&n);
            dp[n]=0;
            for(int i=n-1;i>=0;i--)
            {
                dp[i]=dp[i+1]+1.0*n/(n-i);
            }
    
            printf("Case %d: %lf
    ",cas++,dp[0]);
        }
        return 0;
    }
  • 相关阅读:
    Lua build and install
    tomcat 配置的另外一种方法
    debian vsftp
    git(1)
    jd-gui安装
    debian crash log查看
    ros学习笔记
    51nod 1138 连续整数的和(数学公式)
    51nod 1428 活动安排问题(优先队列)
    Codeforces Round #347 (Div. 2) (练习)
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6291078.html
Copyright © 2011-2022 走看看