495. Kids and Prizes

Time limit per test: 0.25 second(s) 
Memory limit: 262144 kilobytes
input: standard 
output: standard

ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the company organized a contest for kids for the best design of a cardboard box and selected M winners. There are N prizes for the winners, each one carefully packed in a cardboard box (made by the ICPC, of course). The awarding process will be as follows:

  • All the boxes with prizes will be stored in a separate room.
  • The winners will enter the room, one at a time.
  • Each winner selects one of the boxes.
  • The selected box is opened by a representative of the organizing committee.
  • If the box contains a prize, the winner takes it.
  • If the box is empty (because the same box has already been selected by one or more previous winners), the winner will instead get a certificate printed on a sheet of excellent cardboard (made by ICPC, of course).
  • Whether there is a prize or not, the box is re-sealed and returned to the room.

The management of the company would like to know how many prizes will be given by the above process. It is assumed that each winner picks a box at random and that all boxes are equally likely to be picked. Compute the mathematical expectation of the number of prizes given (the certificates are not counted as prizes, of course).

Input

The first and only line of the input file contains the values of N and M ().

Output

The first and only line of the output file should contain a single real number: the expected number of prizes given out. The answer is accepted as correct if either the absolute or the relative error is less than or equal to 10 -9.

Example(s)
sample input
sample output
5 7
3.951424
sample input
sample output
4 3
2.3125


Online Contester Team © 2002 - 2010. All rights reserved.

InputThe first and only line of the input file contains the values of N and M ().OutputThe first and only line of the output file should contain a single real number: the expected number of prizes given out. The answer is accepted as correct if either the absolute or the relative error is less than or equal to 10 -9.Sample Input

sample input
sample output
5 7
3.951424
sample input
sample output
4 3
2.3125

题意:

有n个奖品,m个人排队来选礼物,对于每个人,他打开的盒子,可能有礼物,也有可能已经被之前的人取走了。为最后m个人取走礼物的期望。

思路:

排队取,第1个人取到1个,dp[1]=1;后面的人dp[i]=p取到礼物盒子+dp取到礼物=(n-dp[i-1])/n + dp[i-1];

当然,也可以化简为公式   printf("%.10lf\n",n*1.0*(1-pow((n-1)*1.0/n,m)));

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<algorithm>
using namespace std;
double dp[];
int main()
{
int n,m,i;
while(~scanf("%d%d",&n,&m)){
dp[]=;
for(i=;i<=m;i++) dp[i]=dp[i-]+(n-dp[i-])/n;
printf("%.9lf\n",dp[m]);
}return ;
}

SGU495Kids and Prizes(数学期望||概率DP||公式)的更多相关文章

  1. UVa 11427 Expect the Expected (数学期望 + 概率DP)

    题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...

  2. ZOJ3640Help Me Escape(师傅逃亡系列•一)(数学期望||概率DP)

    Background If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at ...

  3. POJ3682King Arthur's Birthday Celebration(数学期望||概率DP)

    King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. Th ...

  4. SGU495Kids and Prizes 数学期望

    题意: 有n个奖品,m个人排队来选礼物,对于每个人,他打开的盒子,可能有礼物,也有可能已经被之前的人取走了,然后把盒子放回原处.为最后m个人取走礼物的期望. 题解: 本道题与之前的一些期望 DP 题目 ...

  5. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

  6. 【BZOJ 3652】大新闻 数位dp+期望概率dp

    并不难,只是和期望概率dp结合了一下.稍作推断就可以发现加密与不加密是两个互相独立的问题,这个时候我们分开算就好了.对于加密,我们按位统计和就好了;对于不加密,我们先假设所有数都找到了他能找到的最好的 ...

  7. 【BZOJ 3811】玛里苟斯 大力观察+期望概率dp+线性基

    大力观察:I.从输出精准位数的约束来观察,一定会有猫腻,然后仔细想一想,就会发现输出的时候小数点后面不是.5就是没有 II.从最后答案小于2^63可以看出当k大于等于3的时候就可以直接搜索了 期望概率 ...

  8. 【NOIP模拟赛】黑红树 期望概率dp

    这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/ ...

  9. BZOJ1415: [Noi2005]聪聪和可可 最短路 期望概率dp

    首先这道题让我回忆了一下最短路算法,所以我在此做一个总结: 带权: Floyed:O(n3) SPFA:O(n+m),这是平均复杂度实际上为O(玄学) Dijkstra:O(n+2m),堆优化以后 因 ...

随机推荐

  1. 各类人工智能&大数据相关比赛

    比赛技巧:https://zhuanlan.zhihu.com/p/28084438 文章来源: https://www.imooc.com/article/72863 随着近几年人工智能和大数据的快 ...

  2. Lucene 初步 之 HelloWorld

    万恶的源头 HelloWorld 要完成lucene 的配置 需要几个jar包 (如果需要可以留言我私发) 创建索引API分析: 1. Directory: 类代表一个Lucene索引的位置,FSDi ...

  3. ZooKeeper分布式锁简单实践

    ZooKeeper分布式锁简单实践 在分布式解决方案中,Zookeeper是一个分布式协调工具.当多个JVM客户端,同时在ZooKeeper上创建相同的一个临时节点,因为临时节点路径是保证唯一,只要谁 ...

  4. 【三小时学会Kubernetes!(三) 】Service实践

    服务Service Kubernetes 服务资源可以作为一组提供相同服务的 Pod 的入口.这个资源肩负发现服务和平衡 Pod 之间负荷的重任,如图 16 所示. 图16:Kubernetes 服务 ...

  5. Java中的数据结构及排序算法

    (明天补充) 主要是3种接口:List Set Map List:ArrayList,LinkedList:顺序表ArrayList,链表LinkedList,堆栈和队列可以使用LinkedList模 ...

  6. go-statsd项目

    linux命令: 进程:top 收包丢包:netstat -su[c持续输出] go tool pprof: 我们可以使用go tool pprof命令来交互式的访问概要文件的内容.命令将会分析指定的 ...

  7. Learning R笔记(一)

    基本操作 帮助文档:?函数.演示:demo(函数).参数列表:formals(函数),返回为成对列表pairlist. 用all.equal函数检查浮点数是否相等,容忍度默认为1.5e-8,如果相等返 ...

  8. 关于.net4.0中的Action委托

    在使用委托时,若封装的方法无返回值,并且参数在0-7个,可考虑使用.Net4.0中的Action委托,建议使用系统自带的,减少自定义 public delegate void Action<in ...

  9. Verilog HDL Test Bench

    As digital systems becomes more complex,it becomes increasingly important to verify the functionalit ...

  10. 玲珑oj 1128 RMQ模板

    1128 - 咸鱼拷问 Time Limit:3s Memory Limit:128MByte Submissions:380Solved:118 DESCRIPTION 给你两个序列A,B.每个序列 ...