UVA 11427 - Expect the Expected(概率递归预期)
UVA 11427 - Expect the Expected
题意:玩一个游戏。赢的概率p,一个晚上能玩n盘,假设n盘都没赢到总赢的盘数比例大于等于p。以后都不再玩了,假设有到p就结束
思路:递推,dp[i][j]表示玩i盘。赢j盘的概率,那么一个晚上玩了n盘小于p的概率递推式为:
dp(i,j)=dp(i−1,j)∗(1−p)+dp(i−1,j−1)∗p
总和为Q=dp(n,0)+dp(n,1)+...+dp(n,x)(x/n<p)
那么每一个晚上失败的概率Q就求出来了,那么平均玩的天数的期望就利用全期望公式求得为1/Q
代码:
#include <stdio.h>
#include <string.h> const int N = 105;
int t, pz, pm, n;
double f[N][N], p; int main() {
int cas = 0;
scanf("%d", &t);
while (t--) {
scanf("%d/%d%d", &pz, &pm, &n);
p = pz * 1.0 / pm;
memset(f, 0, sizeof(f));
f[0][0] = 1;
double Q = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j * pm <= i * pz; j++) {
f[i][j] = f[i - 1][j] * (1 - p);
if (j) f[i][j] += f[i - 1][j - 1] * p;
if (i == n) Q += f[i][j];
}
}
printf("Case #%d: %d\n", ++cas, (int)(1/Q));
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
UVA 11427 - Expect the Expected(概率递归预期)的更多相关文章
- uva 11427 - Expect the Expected(概率)
题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...
- UVA - 11427 Expect the Expected (概率dp)
Some mathematical background. This problem asks you to compute the expected value of a random variab ...
- 11427 - Expect the Expected(概率期望)
11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...
- UVA 11427 Expect the Expected(DP+概率)
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...
- UVa 11427 - Expect the Expected
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11427 Expect the Expected (期望)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&pa ...
- UVA.11427.Expect the Expected(期望)
题目链接 \(Description\) https://blog.csdn.net/Yukizzz/article/details/52084528 \(Solution\) 首先每一天之间是独立的 ...
- UVA11427 Expect the Expected 概率dp+全概率公式
题目传送门 题意:小明每晚都玩游戏,每一盘赢的概率都是p,如果第一盘就赢了,那么就去睡觉,第二天继续玩:否则继续玩,玩到赢的比例大于p才去睡:如果一直玩了n盘还没完成,就再也不玩了:问他玩游戏天数的期 ...
随机推荐
- 14.4.3.3 Making the Buffer Pool Scan Resistant
14.4.3.3 Making the Buffer Pool Scan Resistant 让Buffer Pool 扫描 相比使用一个严格的LRU算法, InnoDB 使用一个技术来最小化数据的总 ...
- Common lisp菜鸟指南(译)
Common lisp菜鸟指南(译) Common lisp菜鸟指南(译)
- linux kernel的函数与抽象层
在数学领域,函数是一种关系,这种关系使一个集合里的每一个元素对应到另一个(可能相同的)集合里的唯一元素. 在C语言中函数也有这种联系.自变量影响着因变量. 在linux内核驱动编程经常会有抽象层的概念 ...
- (2)入门指南——(7)添加jquery代码(Adding our jQuery code)
Our custom code will go in the second, currently empty, JavaScript file which we included from the H ...
- 【菜鸟看框架】——EF怎样自己主动生成实体
引言 在上一篇博客中给大家介绍了一些关于EF框架的基本知识.让大家对实体架构算是有了一个入门的认识,当然知识 这一篇博客是不能非常清楚的理解实体架构的内涵的.我们须要在实践中自己去不断的研究和探索当中 ...
- linux通过使用mail发送电子邮件
通过外部方法发送的电子邮件 bin/mail默认为本地sendmail发送电子邮件,求本地的机器必须安装和启动Sendmail服务.配置很麻烦,并且会带来不必要的 资源占用.而通过改动配置文件能够使用 ...
- 使用模板类导致error LNK2019: 无法解析的外部符号
原地址 1.定义模板类: template<class T> class Stack {....}; 2.定义模板成员函数: 每个函数头都要以相同的模板声明打头,并将类限定符改成:类名&l ...
- ffmpeg 频中分离 video audio 截取片断
1.获取视频的信息 ffmpeg -i video.avi 2,将图片序列分解合成视频 ffmpeg -i src.mpg image%d.jpg ffmpeg -f image2 -i ...
- 深入浅出Windows BATCH
1.什么是Windows BATCH BATCH也就是批处理文件,有时简称为BAT,是Windows平台上的一种可运行脚本,与*nix(Linux和Unix)上的Shell脚本和其它的脚本(Perl, ...
- POJ训练计划3080_Blue Jeans(串处理/暴力)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11542 Accepted: 4962 Descr ...