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(概率递归预期)的更多相关文章

  1. uva 11427 - Expect the Expected(概率)

    题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...

  2. UVA - 11427 Expect the Expected (概率dp)

    Some mathematical background. This problem asks you to compute the expected value of a random variab ...

  3. 11427 - Expect the Expected(概率期望)

    11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...

  4. UVA 11427 Expect the Expected(DP+概率)

    链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...

  5. UVa 11427 Expect the Expected (数学期望 + 概率DP)

    题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...

  6. UVa 11427 - Expect the Expected

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. UVA 11427 Expect the Expected (期望)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&pa ...

  8. UVA.11427.Expect the Expected(期望)

    题目链接 \(Description\) https://blog.csdn.net/Yukizzz/article/details/52084528 \(Solution\) 首先每一天之间是独立的 ...

  9. UVA11427 Expect the Expected 概率dp+全概率公式

    题目传送门 题意:小明每晚都玩游戏,每一盘赢的概率都是p,如果第一盘就赢了,那么就去睡觉,第二天继续玩:否则继续玩,玩到赢的比例大于p才去睡:如果一直玩了n盘还没完成,就再也不玩了:问他玩游戏天数的期 ...

随机推荐

  1. 改动已有gpg密钥的用户标识及凝视

    /*********************************************************************  * Author  : Samson  * Date   ...

  2. eclipse不能进入debug

    首先说明一下.我肯定是以debug模式启动的.断点程序肯定能走到. 可是一点页面,程序就跳到class文件,而不是Java文件. 解决的方法是:window---preferences---tomca ...

  3. Android学习-----如何使用sqlite对于后台数据交换,sqlite使用例程入门

     SQLite 这是一个非常流行的嵌入式数据库.它支持 SQL 查询,和只使用很少的内存.Android 在集成实施 SQLite,所以每 Android 应用程序能够使用 SQLite 数据库. ...

  4. UpdataData

    MFC中有一个UpdataData函数,有二个参数:TRUE和FLASE,二个参数什么时候用, 开始的时候我也迷糊,后来才发现: UpdataData(TRUE):是把控件上的值刷新到变量中: Upd ...

  5. 推荐一个IT人必备的东西【用过的都懂,让我们的环境越来越好吧】

    有个东西叫IT人手册,不知道各位有用过吗?不过很可惜以前那个关掉了,那个网站说出了我们IT人太多的新声以及一些黑心公司,不过被迫压力下关闭了 我不是托,我只是分享 我觉得这种东西应该存在下去~!!!至 ...

  6. 【linux驱动分析】之dm9000驱动分析(六):dm9000_init和dm9000_probe的实现

    一.dm9000_init 打印出驱动的版本,注冊dm9000_driver驱动,将驱动加入到总线上.运行match,假设匹配,将会运行probe函数. 1 static int __init 2 d ...

  7. mysql导出和导入数据库

    出口 在dos计划,切换到mysql按照该文件夹bin下一个.输入以下命令 mysqldump -u root -p nxu_life > nxu_life2.sql 运行完毕后,就能够看到在b ...

  8. Liftoff Software | Next stop, innovation

    Liftoff Software | Next stop, innovation Previous Next Gate One 1.1 Now Available Submitted by Dan M ...

  9. C# 开发Chrome内核浏览器(WebKit.net)

    原文地址:http://www.cnblogs.com/linyijia/p/4045333.html

  10. 如何不屏蔽Android系统的返回按键

    比如: 第一种方法: public boolean onKeyDown(int keyCode, KeyEvent event) {         // TODO Auto-generated me ...