求解概率的坑题

D - Problem D

Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu

Submit Status

Description

We choose an integer K (K > 0). Then we generate N (N > 0) integers one by one randomly, each of them is in range [0, K - 1], and the appearing probabilities of each interger is the same,they are all 1/K.
Can you tell us the expectation of the number of distinct integers in that N integers?

Input

There is an integer T (1 <= T <= 200) in the first line, means there are T test cases in total.
For each test case, there are two integers K (1 <= K <= 1000), N (1 <= N <= 1000), which have the same meaning as above.

Output

For each test case, you should print the result in one line. You should keep the first 5 digits after the decimal point.

Sample Input

5
1 1
2 2
3 2
3 4
5 3

Sample Output

1.00000
1.50000
1.66667
2.40741
2.44000
 1 #include <cstdio>
 2 double dp[1005];
 3 int main(){
 4     int n,t;
 5     double k;
 6     scanf("%d", &t);
 7     while (t--) {
 8         scanf("%lf %d", &k, &n);
 9         dp[1] = 1.0;
10         for (int i = 2; i <= n; ++i)
11             dp[i] = dp[i-1] + (k - dp[i-1])/k;
12         printf("%.5f\n", dp[n]);
13     }
14     return 0;
15 }

绝对是被坑了,一直都没有想到通过递推的的方式来求解,结果计算越来越复杂,后来就不能忍了,受不了,以后坚决不能犯这样的低级错误……

求解概率的坑题

时间: 2024-07-31 00:42:53

求解概率的坑题的相关文章

【BZOJ-1952】Area [坑题] 仙人掌DP + 最大点权独立集(改)

1952: [Sdoi2010]Area Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][Discuss] Description 小猪iPig来到了一个叫做pigsty的城市里,pigsty是一座专门为小猪所准备的城市,城市里面一共有n个小区给小猪们居住,并且存在许多条无向边连接着许多小区.因为这里是一个和谐的城市,所以小猪iPig准备在这个城市里面度过他的余生.若干年之后小猪iPig

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t

hdu 5455 Fang Fang 坑题

Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 Description Fang Fang says she wants to be remembered.I promise her. We define the sequence F of strings.F0 = ‘‘f",F1 = ‘‘ff",F2 = ‘‘cff",F

HDU 1498 50 years, 50 colors(最小点覆盖,坑题)

50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1635    Accepted Submission(s): 892 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating

13年山东省赛 The number of steps(概率dp水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Memory Limit: 128 M Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two ro

hdu 4920 Matrix multiplication(矩阵坑题)

http://acm.hdu.edu.cn/showproblem.php?pid=4920 被这道题虐了一下午,啥也不说了.继续矩阵吧. 超时就超在每步取余上,要放在最后取余,再者注意三个循环的次序. #include <stdio.h> #include <map> #include <set> #include <stack> #include <queue> #include <vector> #include <cma

湘潭大学OJ1200ProblemCRC(摸拟,坑题)

题目描述 现实中的网络通讯不够理想,经常会有bit从0变1,从1变0...为了检验是否出错 需要用到循环冗余校验CRC CRC冗余检验码包含两个部分 k位信息位+n位校验位,可由以下的步骤得到: 1.将要传送的数据分段,每段k个bit,如果不足k位用0补齐 2.对于每个长度为k的01序列M, 先在M后面加n个0得到新的M'. 3.选定一个(n+1)位的01序列做为除数P,对M'做**模2的除法,得到一个n位的余数R(即校验位). 4.将R接到M的后面就得到了M的 CRC冗余检验码 请写一个程序模

POJ 2516 Minimum Cost(最小费用最大流,坑题)

题目链接:http://poj.org/problem?id=2516 题意:有N个店,M个供货商,K种商品.已知供货商的仓库里每种商品的数量以及每种商品运送到每个店的费用,每个店铺对各种商品的需求数量,求最少话费. Input  第一行:N,M,K. 然后1 - N行,每行 K列 ,第I行第J个数代表 第I个店铺 需要第J种物品多少件. 然后 N+1 - M行  ,每行 K列 , 第I行第J个数代表 第I个供货商 有第J种物品多少件. 然后是K个矩阵  ,每个N行M列,第ji个矩阵的第i行第j

hdu 4738 无向图缩点断桥 // 细节坑题

Caocao's Bridges 题意:给个无向图,求出边权最小的桥. 一看,直接缩点,若无桥,输出-1,有桥,遍历下边,更新最小..分分钟搞定,以为IA的..一交wa... 坑点:1:若原图不连通,则无须派人去!输出0!: 2:若桥的权是0,则还有派一个人把炸弹拿去,输出1! 3:有重边.(按多条边算). 哎!记住这个教训!以后做题 1:考虑边界或者特殊数据!(边权为0!n==1等) 2:考虑原图连通性!(这次考虑了原图就强连通..没有考虑根本不连通!) 3:重边.这题的重边是按重边算(不是一