UVa 11427 - Expect the Expected
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2422
每一天的情况是相互独立的
d[i][j] 表示这一天比了i次赢了j次还不能回去的概率
这样就可以 求出比了n次 仍然不能回去(垂头丧气回去,以后再也不玩了)的概率 Q
然后可以经过推导 最终期望为 1/Q
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include<queue> #define ull unsigned long long
#define ll long long
#define lint long long
using namespace std; const int INF=0x3f3f3f3f;
const int N=1003;
double d[N][N]; int main()
{
//freopen("data.in","r",stdin);
int T;
scanf("%d",&T);
for(int c=1;c<=T;++c)
{
printf("Case #%d: ",c);
int n;
int a,b;
double p;
scanf("%d/%d %d",&a,&b,&n);
p=1.0*a/b;
//cout<<a<<" "<<b<<" "<<n<<" "<<p<<endl;
for(int i=0;i<=n;++i)
for(int j=0;j<=n;++j)
d[i][j]=0.0;
d[0][0]=1.0;
for(int i=1;i<=n;++i)
for(int j=0;j<=i;++j)
{
if(1.0*j/i<=p)
{
d[i][j]+=d[i-1][j]*(1-p);
if(j-1>=0)
d[i][j]+=d[i-1][j-1]*(p);
}
}
double sum=0.0;
for(int j=0;j<=n;++j)
{
sum+=d[n][j];
}//cout<<sum<<endl;
printf("%d\n",(int)(1.0/sum));
}
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(概率)
题目链接: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 ...
- UVA 11427 Expect the Expected (期望)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&pa ...
- 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(期望)
题目链接 \(Description\) https://blog.csdn.net/Yukizzz/article/details/52084528 \(Solution\) 首先每一天之间是独立的 ...
- 11427 - Expect the Expected(概率期望)
11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...
- UVA 11427 (概率DP+期望)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...
随机推荐
- [转载] 构建微服务:使用API Gateway
原文: http://mp.weixin.qq.com/s?__biz=MzA5OTAyNzQ2OA==&mid=206889381&idx=1&sn=478ccb35294c ...
- html块级元素和内联元素小结
Block element 块级元素 顾名思义就是以块显示的元素,高度宽度都是可以设置的.比如我们常用的<div>.<p>.<ul>默认状态下都是属于块级元素.块级 ...
- Python学习(5)条件语句
目录 Python 条件语句 Python 简单的语句组 Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了 ...
- Android开源库--Gson谷歌官方json解析库
官方文档地址:http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html 官方网站:http://code.go ...
- 转:C/C++基本数据类型所占字节数
参考:http://blog.csdn.net/vast_sea/article/details/8076934 关于这个基本的问题,很早以前就很清楚了,C标准中并没有具体给出规定那个基本类型应该是多 ...
- D3.js 简介和安装
一.What´s D3.js D3.js是一种数据操作类型的javascript库(也可视其为插件):结合HTML,SVG和CSS,D3可以图形化的,生动的展现数据. D3 的全称是(Data-Dri ...
- 获取iframe外边数据
http://biancheng.dnbcw.info/javascript/178184.html
- Canu Parameter Reference(canu参数介绍)
链接:Canu Parameter Reference To get the most up-to-date options, run canu -options The default values ...
- graph-tool文档(一)- 快速开始使用Graph-tool - 1.创建和操纵图
目录: 快速开始使用graph-tool 创建和操纵图 -- 遍历顶点和边 ----- 遍历所有顶点或边 ----- 遍历一个顶点的neighbourhood 名词解释: instante:实例 di ...
- vbox下android分辨率设置
VBoxManage setextradata "android" "CustomVideoMode1" "1280x800x16" 1. ...