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局, ...
随机推荐
- Java中JTree的简单案例
package ch12; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; /** * Created by ...
- virtualbox中centos系统配置nat+host only上网(zhuan)
http://www.cnblogs.com/leezhxing/p/4482659.html **************************************************** ...
- shell脚本中获取本机ip地址的方法
ipaddr='172.0.0.1' ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/ ...
- Hexo+github 搭建个人博客(一)
一.软件环境准备 1.安装git windows下载exe安装:linux 执行 apt-get install git-core 安装 2.安装Node.js windows使用 msi 文件进行安 ...
- SSH2 架构常用注解
1. @Repository 将 DAO 类声明为 Bean 2.@Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次. 3.@Service 通常作用在业务层 ...
- 游戏引擎/GUI的设计与实现-序
几年前写<嵌入式GUI FTK设计与实现>,没写几篇就停止更新了.当时自己研究过MicroWindows, X Window, DirectFB, GTK+和Android的GUI,又写过 ...
- IOS开发—UIDatePicker 日期/时间选取器(滚轮)
UIDatePicker 是一个控制器类,封装了 UIPickerView,但是他是UIControl的子类,专门用于接受日期.时间和持续时长的输入.日期选取器的各列会按照指定的风格进行自动配置,这样 ...
- Machine Learning for hackers读书笔记(三)分类:垃圾邮件过滤
#定义函数,打开每一个文件,找到空行,将空行后的文本返回为一个字符串向量,该向量只有一个元素,就是空行之后的所有文本拼接之后的字符串 #很多邮件都包含了非ASCII字符,因此设为latin1就可以读取 ...
- 3.3 使用Code First数据库迁移
当Entity Framework Code First的数据模型发生异动时,默认会引发一个System.InvalidOpertaionException异常.一种解决方法是在Global.asax ...
- (08)odoo继承机制
* 全局的引用 所有的的模型定义外,都在注册中心注册了,我们可以用全局变量来引用这些模型 self.env[mode name] 比如得到合作伙伴这个模型 self.evn['res.pa ...