• 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;
    }
  • 相关阅读:
    [转]Delphi中进行延时的4种方法
    [转]delphi 删除动态数组的指定元素
    vue-transition-fade
    移动端list布局,左边固定,右边自适应
    移动端弹窗
    多行文字超出省略显示
    jsonp
    barba 页面渲染
    barba.js 优化页面跳转用户体验
    页面返回无刷新
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6291078.html
Copyright © 2020-2023  润新知