LightOJ - 1248 Dice (III) 期望 + dp

题目大意:给出一个n面的色子,问看到每个面的投掷次数期望是多少

解题思路:水题啊,竟然被卡了那么久,也是醉了,给题目所给的那个样例误导了。。。不怪那个 怪自己太弱了,还得继续训练啊。。。

设dp[i]表示扔到i个不同面的期望,那么

dp[i + 1] = i / n * dp[i + 1] + (n - i) / n * dp[i] + 1

整理得

dp[i + 1] = n / (n - i) + dp[i] + 1

#include<cstdio>
#define maxn 100010
double f[maxn];
int main() {
    int test,n, cas = 1;
    scanf("%d", &test);
    while(test--) {
        scanf("%d", &n);
        f[0] = 0;
        for(int i = 0; i < n; i++)
            f[i + 1] = f[i] + (1.0 * n / (n - i));
        printf("Case %d: %.7lf\n", cas++, f[n]);
    }
    return 0;
}
时间: 2024-07-30 10:17:41

LightOJ - 1248 Dice (III) 期望 + dp的相关文章

LightOj 1248 - Dice (III)(几何分布+期望)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个面第一次出现的概率是p3 (n-2)/n; ... 第 i 个面第一次出现的概率是pi (n-i+1)/n; 先看一下什么是几何分布: 几何分布: 在第n次伯努利试验中,试验 k 次才得到第一次成功

LightOJ 1248 - Dice (III) 给一个质地均匀的n的骰子, 求投掷出所有点数至少一次的期望次数。(概率)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1248 投掷出第一个未出现的点数的概率为n/n = 1, 因为第一次投掷必然是未出现的. 第二个未出现的点数第一次出现的概率为 (n - 1) / n,因为有一个已经投掷出现过. 第i个未出现的点数第一次出现的概率为 (n - i) / i, 这满足几何分布. 其期望E = 1/p 所以期望为n *(1 + 1 / 2 + 1 / 3 + ... 1 / n). #include<

【非原创】LightOj 1248 - Dice (III)【几何分布+期望】

学习博客:戳这里 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个面第一次出现的概率是p3 (n-2)/n; ... 第 i 个面第一次出现的概率是pi (n-i+1)/n; 先看一下什么是几何分布: 几何分布: 在第n次伯努利试验中,试验 k 次才得到第一次成功的机率为p.详细的说是:前k-1次皆失败,第k次成功的概率为p. 几何分布的期望E(X) = 1/p;

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

Light OJ 1248 - Dice (III) 概率DP

n个面的骰子 求每个面至少扔到一次的期望值 设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0] 因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况 所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #include <cstdio> #include <cstring> #define imax 100005

[lLOJ 1248] Dice (III)

G - Dice (III) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that

light oj 1248 - Dice (III)(期望)

Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that means when you throw the dice, the probability of occurring any face is equal.

lightoj 1248-G - Dice (III) (概率dp)

题意:给你n个面的骰子,问扔出所有面的期望次数. 虽然这题挺简单的但还是要提一下.这题题目给出了解法. E(m)表示得到m个不同面的期望次数. E(m+1)=[((n-m)/n)*E(m)+1]+(m/n)*E(m+1); 想必((n-m)/n)*E(m)+1这个很好理解吧,当得到m个面时他有((n-m)/n)的概率得到没得到过的面 而(m/n)*E(m+1)不太好理解为什么,其实题目已经给出解释了,如果他有(m/n)的概率出到不同 面也有1-(m/n)的概率得到相同面,所以直接加上((n-m)

1248 - Dice (III)

  PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that m