sgu 495. Kids and Prizes (简单概率dp 正推求期望)
495. Kids and Prizes
Memory limit: 262144 kilobytes
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).
The first and only line of the input file contains the values of N and M ().
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.
sample input |
sample output |
5 7 |
3.951424 |
sample input |
sample output |
4 3 |
2.3125 |
题意:
有n个奖品放在n个盒子,进行m次选择,每次只能选则一个盒子,如果选到含有奖品的话就把盒子里奖品拿走,盒子始终仍留着。问最终得到到奖品数的期望值。
分析:
一看见求期望想逆推,但是发现逆推没办法写初始条件,这是因为取的次数不少无限的,
只能取m次。
d[i]代表到第i个人取到奖品数的期望,显然d[i]等于上一个人取到的奖品数加上这个人取到的奖品数,
这个人取到的奖品数为1的概率为(n-d[i-1])/n,取到奖品数为0的概率为d[i-1]/n,即期望为
d[i-1]+1*(n-d[i-1])/n+0*d[i-1]/n。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e5+;
using namespace std;
double d[maxn]; int main()
{
int n, m, i, j;
while(~scanf("%d%d", &n, &m))
{
d[] = ;
for(i = ; i <= m; i++)
d[i] = d[i-]+1.0*((double)n-d[i-])/(double)n;
printf("%.9lf\n", d[m]);
}
return ;
}
sgu 495. Kids and Prizes (简单概率dp 正推求期望)的更多相关文章
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- SGU 495. Kids and Prizes( 数学期望 )
题意: N个礼品箱, 每个礼品箱内的礼品只有第一个抽到的人能拿到. M个小孩每个人依次随机抽取一个, 求送出礼品数量的期望值. 1 ≤ N, M ≤ 100, 000 挺水的说..设f(x)表示前x ...
- hdu 4336 Card Collector (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Aeroplane chess(简单概率dp)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- 495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 学习:当一条路走不通,换一种对象考虑,还有考虑对立面. 495. Kids and Pr ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
随机推荐
- 如何使用CSL(翻译总结自TI官方文档)
为了使用CSL来进行编译和连接,必须先配置CCS开发环境. 1.指定目标设备 Project/options/complier/preprocessor,在define symbols中输入设备支持符 ...
- [HTML/CSS]display:none和visibility:hidden的区别
写在前面 在群里有朋友问这样一个问题,display:none的标签,影响了布局.这就引出了本篇这样的问题,印象中display:none的块元素是不占位置的. 一个例子 <!DOCTYPE h ...
- CSS3弹性盒模型,Flex布局教程
布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现. CSS3中引入flex的弹性盒模型 ...
- POJ 3185
The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4088 Accepted: 1609 D ...
- H5+ and mui学习记录
基础 1.H5+ 定义实现了一些调用原生方法的对象 2.其他的原生方法可以通过Native.js调用 webview 3.webview是调用原生界面的H5+对象 4.单个webview只承载单个页面 ...
- .NET Framework 框架简述01
NET技术可以以规范和实现两部分来划分. 规范: 公共语言架构(Common Language Infrastructure, CLI),主要包括 1.通用类型系统(Common Type S ...
- sizeof学习理解
以下内容转自: http://www.cnblogs.com/ComputerG/archive/2012/02/02/2335611.html 博问 闪存 首页 新随笔 联系 管理 随笔- 72 ...
- Good Bye 2014 D. New Year Santa Network 图论+期望
D. New Year Santa Network New Year is coming in Tree World! In this world, as the name implies, th ...
- Useful for Android the development engineer from Github
Original:http://sysmagazine.com/posts/216591/ Many plowing on open space Github, I found assemblage ...
- lintcode: 寻找旋转排序数组中的最小值
寻找旋转排序数组中的最小值 假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2). 你需要找到其中最小的元素. 你可以假设数组中不存在重复的 ...