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盘还没完成,就再也不玩了:问他玩游戏天数的期 ...
随机推荐
- [置顶] Oracle 11g Data Guard Role Transitions: Failover
Role TransitionsInvolving Physical Standby Databases A database operates in one of the following mut ...
- flashcache中应用device mapper机制
Device Mapper(DM)是Linux 2.6全面引入的块设备新构架,通过DM可以灵活地管理系统中所有的真实或虚拟的块设备. DM以块设备的形式注册到Linux内核中,凡是挂载(或者说“映射” ...
- POJ 1160 Post Office (动态规划)
Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15412 Accepted: 8351 Desc ...
- Swift - 多行文本输入框(UITextView)的用法
1,多行文本控件的创建 1 2 3 4 var textview=UITextView(frame:CGRectMake(10,100,200,100)) textview.layer.borderW ...
- html怎么引用css
<head> <title>统一站内风格</title> <link rel="stylesheet" type="text/c ...
- Android显示GIF图片
今天我们研究一下怎样在Android手机上显示GIF动态图片 首先须要在src文件夹下新建一个自己定义的View.代码例如以下: </pre><pre name="code ...
- RF+Selenium2Library+Sikuli集成环境搭建
Sikuli是通过截图来编写代码的脚本语言,他是对于Selenium不好处理的一些模态窗口.flash等的利器.废话少说,直接开始安装吧.安装RF+Selenium2Library的环境这里就不说了, ...
- linux串口编程总结
串口本身.标准和硬件 † 串口是计算机上的串行通讯的物理接口.计算机历史上,串口以前被广泛用于连接计算机和终端设备和各种外部设备.尽管以太网接口和USB接口也是以一个串行流进行数据传送的.可是串口连接 ...
- poj 3450 Corporate Identity
题目链接:http://poj.org/problem?id=3450 题目分类:后缀数组 题意:求n个串的最长公共字串(输出字串) //#include<bits/stdc++.h> # ...
- [Android学习笔记]获取view的尺寸和坐标
对于UI方面很多时候需要获取它的很多信息,具体情况见view的文档 View文档 http://developer.android.com/training/index.html 常用方法:获取vie ...