SGU 495 — Kids and Prizes
来源:互联网 发布:seo诊断报告 编辑:程序博客网 时间:2024/05/14 08:28
原题:http://acm.sgu.ru/problem.php?contest=0&problem=495
题意:有n个奖品,奖品各自放在盒子里,m个人轮流选取,若盒中有奖品则拿走,但不管怎样,盒子依然放回。问得到奖品数的期望。
思路:1)数学推理
每个奖品不被选中的概率为(1-1/n)^m,那么每个奖品被选中的概率为1-(1-1/n)^m;
所以总期望为n*(1-(1-1/n)^m);
2)概率dp
dp[i]表示到第i个人得到奖品数的期望;所以dp[i]等于上一个人得到的奖品数加上这个人得到的奖品数;
若此人得到了奖品则概率为(n-dp[i-1])/n, 若没得到则概率为dp[i-1]/n;
所以dp[i] = dp[i-1]+1*(n-dp[i-1])/n+0*dp[i-1]/n;
#include<stdio.h>#include<math.h>double n, m;int main(){while(scanf("%lf%lf", &n, &m)!=EOF)printf("%.9f\n", n*(1-pow((1-1/n), m)));return 0;}
#include<stdio.h>#include<string.h>double n;int m;double dp[100005];int main(){while(scanf("%lf%d", &n, &m)!=EOF){memset(dp, 0, sizeof(dp));dp[1] = 1;for(int i = 2;i<=m;i++)dp[i] = dp[i-1]+(n-dp[i-1])/n;printf("%.9f\n", dp[m]);}return 0;}
0 0
- SGU 495 — Kids and Prizes
- Kids and Prizes - SGU 495
- SGU 495 Kids and Prizes
- SGU 495 Kids and Prizes
- SGU 495 Kids and Prizes(概率dp)
- SGU 495 Kids and Prizes(期望)
- sgu 495 Kids and Prizes 求概率
- Sgu 495 Kids and Prizes (概率dp)
- SGU 495 Kids and Prizes(期望)
- sgu 495 Kids and Prizes 概率dp
- SGU 495 Kids and Prizes 概率 二项分布
- SGU 495 Kids and Prizes (二项分布)
- SGU 495 Kids and Prizes 概率dp
- SGU 495 Kids and Prizes(概率dp)
- SGU 495 Kids and Prizes(概率)
- SGU 495 Kids and Prizes [期望]
- [概率dp] sgu 495 Kids and Prizes
- SGU 495. Kids and Prizes
- 错误1error C2040: “menu”:“auto”与“cocos2d::Menu *”的间接寻址级别不同
- online_judge_1080
- 微信投票刷票器软件怎么用
- Flex Image 运行时加载图片不显示
- 随便说说
- SGU 495 — Kids and Prizes
- (转) Cocoa 框架 For iOS(一) 框架的介绍,Objectivie-C运行时能力的解析等
- apt-get 命令
- 各种常用的JSON接口,开动你的大脑你就可以做出各种应用,值得收藏
- 【LeetCode】021.Merge Two Sorted Lists
- 第二章第二题
- Matlab 提取矩阵 某一行 或者 某一列 的方法
- 题6
- 第二章第六题