uva 11427 - Expect the Expected(概率)
题目链接:uva 11427 - Expect the Expected
题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结束游戏,若n局后仍没有,就会不开心,然后以后再也不完牌,问说你最多会玩多少个晚上。
解题思路:当j/i ≤ p时有dp(i-1,j) (1-p) + dp(i-1, j-1)
p,其它dp(i,j) = 0.Q=∑d(n,i)
列出数学期望公式:
EX=Q+2Q(1−Q)+3Q(1−Q)2+…
s=EXQ=1+2(1−Q)+3(1−Q)2+…
(1−Q)∗s=(1−Q)+2(1−Q)2+3(1−Q)3+…
EX=Qs=1+(1−Q)+(1−Q)2+(1−Q)3…
为等比数列,依据等比数列求和公式,n趋近无穷大是为1/Q
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105;
double dp[maxn][maxn];
int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
int a, b, n;
scanf("%d/%d%d", &a, &b, &n);
double p = (double)a / b;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
dp[0][1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j * b <= a * i; j++) {
dp[i][j] = dp[i-1][j] * (1-p);
if (j)
dp[i][j] += dp[i-1][j-1] * p;
}
}
double q = 0;
for (int i = 0; i * b <= a * n; i++)
q += dp[n][i];
printf("Case #%d: %d\n", kcas, (int)(1/q));
}
return 0;
}
uva 11427 - Expect the Expected(概率)的更多相关文章
- UVA 11427 - Expect the Expected(概率递归预期)
UVA 11427 - Expect the Expected 题目链接 题意:玩一个游戏.赢的概率p,一个晚上能玩n盘,假设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盘还没完成,就再也不玩了:问他玩游戏天数的期 ...
随机推荐
- delphi 精要-读书笔记(内存分配释放)
delphi 精要-读书笔记(内存分配释放) 1.内存分为三个区域:全局变量区,栈区,堆区 全局变量区:专门存放全局变量 栈区:分配在栈上的变量可被栈管理器自动释放 堆区:堆上的变量内存必须人 ...
- SilkTest Q&A 4
Q31.如何在inc文件里面写函数? A31.在你在inc文件(例如demo.inc)里写好函数以后,你需要使用Use path/Use file来指定指定它们. 在SilkTest中->Opt ...
- 中科燕园GIS外包----机场project地理信息系统EGIS
对于大型机场建设project,不管project建设过程中.还是project建设完毕后.进入执行和维护阶段.必然要产生和使用到大量的各式各样的信息资料,包含project项目过程管理控制类文档,p ...
- Virtualbox mouse move in and out and file share with windows
How to use Virstalbox to share files with Linux and Windows, and to move the mouse in and out Virtua ...
- Ubuntu 问题解决汇总
汇总一些ubuntu相关的问题 1.Ubuntu支持安装多媒体播放插件(新系统安装后必备) ubuntu-restricted-extras package allows users to insta ...
- html5css3杂记
最新版本号的safari.chrome.firefox以及opera支持某些html5特性.ie9将支持某些html5特性. html5提供了展现视频的标准<video>支持ogg及mpe ...
- C语言数组
在C语言中,对于三维或三维以上数组的使用并没有很好的支持,而且使用率也非常的低,后面会对三维数组做一些简单的分析,这篇文章主要以二维数组来探讨一些C语言中数组使用的相关概念和技巧. 1 一个var[i ...
- Note for video Machine Learning and Data Mining——Linear Model
Here is the note for lecture three. the linear model Linear model is a basic and important model in ...
- Mysql怎样删除以“#sql-”开头的暂时表
author:skate time:2014/09/28 Mysql怎样删除以"#sql-"开头的暂时表 现象:在重建索引后,发现Mysqlserver的磁盘空间快满了 在用例如以 ...
- CentOS 7 安装MySql Server 5.6
1. 安装MySql Server 在/etc/yum.repos.d/目录下添加以下文件mysql-community.repo文件,内容如下: [mysql56-community] name=M ...