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 the dice is fair, that means when you throw the dice, the probability of occurring any face is equal.

For example, for a fair two sided coin, the result is 3. Because when you first throw the coin, you will definitely see a new face. If you throw the coin again, the chance of getting the opposite side is 0.5, and the chance of getting the same side is 0.5. So, the result is

1 + (1 + 0.5 * (1 + 0.5 * ...))

= 2 + 0.5 + 0.52 + 0.53 + ...

= 2 + 1 = 3

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 105).

Output

For each case, print the case number and the expected number of times you have to throw the dice to see all its faces at least once. Errors less than 10-6 will be ignored.

Sample Input

5

1

2

3

6

100

Sample Output

Case 1: 1

Case 2: 3

Case 3: 5.5

Case 4: 14.7

Case 5: 518.7377517640

故设dp[i]为在已经扔出了i个不同面的情况下扔出n个不同面的期望次数,dp[n]=0,答案为dp[0]
则\(dp[i]=dp[i]*\frac{i}{n}+dp[i+1]*\frac{n-i}{n}+1\)

移项得:\(dp[i]=dp[i+1]+\frac{n}{n-i}\)

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 100010 int main()
{
int T,n,iCase=;
double dp[N];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
dp[n]=;
for(int i=n-;i>=;i--) dp[i]=dp[i+]+n*1.0/(n-i);
printf("Case %d: %.7f\n",iCase++,dp[]);
}
return ;
}

[LOJ 1248] Dice (III)的更多相关文章

  1. LightOJ - 1248 Dice (III) —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1248 1248 - Dice (III)    PDF (English) Statistics Forum Tim ...

  2. LightOJ 1248 Dice (III) (期望DP / 几何分布)

    题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...

  3. 1248 - Dice (III)

    1248 - Dice (III)   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given ...

  4. LightOJ 1248 Dice (III) 概率

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

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

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1248 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望 ...

  6. LightOJ 1248 Dice (III)

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

  7. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

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

    学习博客:戳这里 题意:有一个 n 面的骰子,问至少看到所有的面一次的所需 掷骰子 的 次数的期望: 第一个面第一次出现的概率是p1 n/n; 第二个面第一次出现的概率是p2 (n-1)/n; 第三个 ...

  9. Day11 - B - Dice (III) LightOJ - 1248

    设dp_i为已经出现了i面,需要的期望次数,dp_n=0 那么dp_i= i/n*dp_i + (n-i)/n*dp_(i+1) + 1 现在已经i面了,i/n的概率再选择一次i面,(n-i)/n的概 ...

随机推荐

  1. proguardgui.bat来混淆已有的jar包

    1.U:\android-sdk\tools\proguard\bin\找到 proguardgui.bat,双击就可以弹出一个混淆的界面 2.加入不要混淆的,比如我们用的系统的,还有别人的jar 3 ...

  2. 二十、mysql mysqldump备份工具

    .备份所有数据库 mysqldump -uroot -p --all-database > c:\all.sql 备份所有数据库到c盘下的all,sql文件 .备份某个数据库 mysqldump ...

  3. PDF合并

    要求:将多个table导出到一个PDF里,然后打印. 问题分析:要求将四个table放一个PDF打印,四个table的列各不相同,第一个是表头,其他三个是列表,列比表头多很多,如果直接生成一个exce ...

  4. easy ui datagrid 动态绑定数据并绑定链接,进行操作

    ①.绑定datagrid,formatter { field: 'ShopId', title: '操作', width: 200, align: 'left', formatter: showSho ...

  5. input输入框的各种样式

    输入框景背景透明: <input style="background:transparent;border:1px solid #ffffff"> 鼠标划过输入框,输入 ...

  6. Elasticsearch升级至1.x后API的变化-三

    请支持原创:http://www.cnblogs.com/donlianli/p/3841762.html   1.索引格式 1.x之前的版本,被索引的文档type会同时出现在url和传输的数据格式中 ...

  7. fzu 2105 Digits Count ( 线段树 ) from 第三届福建省大学生程序设计竞赛

    http://acm.fzu.edu.cn/problem.php?pid=2105 Problem Description Given N integers A={A[0],A[1],...,A[N ...

  8. TCP/IP协议原理学习笔记

    昨天学习了杨宁老师的TCP/IP协议原理第一讲和第二讲,主要介绍了OSI模型,整理如下: OSI是open system innerconnection的简称,即开放式系统互联参考模型,它把网络协议从 ...

  9. vbe6ext.olb不能被加载 宏内存溢出

    今天想玩一下PowerPoint的宏,却发现玩不起来!!! 另外,每次打开ppt时都会提示vbe6ext.olb不能加载. 网上说重新下载个vbe6ext.olb然后复制到相应的路径.我也试着下载,然 ...

  10. 1047: [HAOI2007]理想的正方形 - BZOJ

    Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小.Input 第一行为3个整数,分别表示a,b,n的值第二行至第a ...