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盘还没完成,就再也不玩了:问他玩游戏天数的期 ...
随机推荐
- fastjson 之常见的数据类型与json的相互转换
public class FastJsonTest1 { /** * 数组转json格式字符串 */ public void array2Json(){ String[] arr = {"b ...
- 《c陷阱与缺陷》笔记--移位运算
#include <stdio.h> int main(void){ int a = 2; a >> 32; a >> -1; a << 32; a & ...
- Delphi透明组件开发(去掉自己的csOpaque,去掉父控件的WS_CLIPCHILDREN,增加WS_EX_TRANSPARENT,截获WM_ERASEBKGND,然后在WM_DRAWITEM里画) good
透明的控件, 一般继承自TGraphicControl的(就是那些没有handle属性, 不能有focus的控件, 如image)都有Transparent属性. 对TWinControl类的控件, ...
- gcc -D 传值给代码,默认值为1
gcc -D 传值给代码,默认值为1 -D 参数可以给代码中的宏打开一扇门.简单的代码#include <stdio.h> #ifdef WHO #define NAME "jo ...
- Common Lisp Style Guide - Ariel Networks Labs
Common Lisp Style Guide - Ariel Networks Labs Common Lisp Style Guide
- 通过加载Kernel32来动态判断 当前操作系统32bit还是64bit
工作原理:通过加载Kernel32来获取IsWow64Process 函数然后通过函数的地址操作,执行函数的操作. 在程序中只要我们获取了一个函数的地址,就可以找到正确的方法执行这个函数. 但是这种方 ...
- iOS学习——iOS国际化(十二)
开发的移动应用更希望获取更多用户,走向世界,这就需要应用国际化,国际化其实就是多语言.这篇文章介绍Xcode4.5以后的国际化,包括应用名国际化和应用内容国际化.如果是Xcode4.5之前版本请参考. ...
- hdoj 1258 SUM IT UP
程序的思想是:输入数据是,先使用快排对其从大到小进行排序,然后记录相同数据的个数,比如4 3 3 2 2 1 1,最后的数据变成4 3 2 1 ,并且同时数据的个数f[]变成1 2 2 2 然后就是遍 ...
- achieve aop through xml
The main way to achive AOP is deploying a xml file. Now a xml file is presented to be a explanation ...
- Struts2 后台action接收 jsp页面中checkbox中的值
如前端页面jsp中的标签为: <form action="myurl"> <input type="checkbox" name=" ...