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;
    }
  • 相关阅读:
    Node.js 0.12: 正确发送HTTP POST请求
    pm2 常用命令
    IntelliJ IDEA Configuring projects
    socket.io入门整理教程
    幂等函数
    Linux 下 ps 命令
    Linux 下 tail 命令
    Linux下chmod命令
    Linux下ll命令与ls -l
    Thrift——初学
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6291078.html
Copyright © 2011-2022 走看看