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盘还没完成,就再也不玩了:问他玩游戏天数的期 ...
随机推荐
- PHP从数据库获取的下拉树
<?php include "config.php"; include "mysql.php"; $db = new Mysql('test'); //几 ...
- javascripte (三) 改变html图像
<script> function changeImage(){ element=document.getElementById("myimage") if (elem ...
- How to Design Programs, Second Edition
How to Design Programs, Second Edition How to Design Programs, Second Edition
- UVA 10313(完全背包变形)
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...
- [置顶] 深圳华为BSS公共部件 (BI 商业智能 Java Javascript)
深圳华为BSS公共部件 部门招聘 招聘面试地点:大连,西安 工作地点:深圳 时间:2013年9月7日 联系方式:dawuliang@gmail.com 18675538182 有兴趣的同学,可以直接电 ...
- iOS 开发百问(6)
61.警告"addexplicit braces to avoid dangling else" 所谓"危急的else"是相似这种代码: if(a== 10) ...
- linux串口编程总结
串口本身.标准和硬件 † 串口是计算机上的串行通讯的物理接口.计算机历史上,串口以前被广泛用于连接计算机和终端设备和各种外部设备.尽管以太网接口和USB接口也是以一个串行流进行数据传送的.可是串口连接 ...
- 使用AjaxFileUpload.js实现文件异步上�
ajax是无法提交文件的,所以在上传图片并预览的时候,我们常常使用Ifame的方法实现看似异步的效果.可是这样总不是非常方便的,AjaxFilleUpload.js对上面的方法进行了一个包装,使得我们 ...
- NET平台机器学习组件-Infer.NET
NET平台机器学习组件-Infer.NET(三) Learner API—数据映射与序列化 阅读目录 关于本文档的说明 1.基本介绍 2.标准数据格式的映射 3.本地数据格式映射 4.评估数据格式映射 ...
- iOS8开发~Swift(一)入门
一.概论及Swift介绍 iOS7刚公布多时候,苹果引入了JavaScriptCore.framework用来处理JavaScript,看到了能够接触其它编程语言的契机,使iOS程序猿不用吊死在OC这 ...