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的更多相关文章

  1. UVA 11427 - Expect the Expected(概率递归预期)

    UVA 11427 - Expect the Expected 题目链接 题意:玩一个游戏.赢的概率p,一个晚上能玩n盘,假设n盘都没赢到总赢的盘数比例大于等于p.以后都不再玩了,假设有到p就结束 思 ...

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

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

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

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

  4. UVA 11427 Expect the Expected (期望)

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

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

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

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

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

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

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

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

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

  9. UVA 11427 (概率DP+期望)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...

随机推荐

  1. Java编程思想学习笔记_5(IO流)

    一.用DataInputStream读取字符 可以使用available方法查看还有多少可供存取的字符.示例如下: public class Test1 { public static void ma ...

  2. POJ 3468 线段树裸题

    这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...

  3. Spring源码分析心得-Bean的读取和注册

    Spring广泛的被使用足以证明它的价值,成功的东西自然值得我们深入学习.有很多人说的熟悉Spring也只是简单的使用经验,当我发现我也是其中一员时我很恐惧,所以开始扒源码,准备深入了解,话不多说,直 ...

  4. Http报头Accept与Content-Type的区别

    Http报头Accept与Content-Type的区别 1.Accept属于请求头, Content-Type属于实体头. Http报头分为通用报头,请求报头,响应报头和实体报头. 请求方的http ...

  5. 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment

    总结: 内部函数,不修改全局变量可以访问全局变量 内部函数,修改同名全局变量,则python会认为它是一个局部变量 在内部函数修改同名全局变量之前调用变量名称(如print sum),则引发Unbou ...

  6. VS2013和VS2008项目的互通

    VS2013和VS2008项目的互通,大家可能都查到了百度经验里面的一个帖子: http://jingyan.baidu.com/article/f54ae2fc3c3adc1e92b849de.ht ...

  7. 多线程调用HttpWebRequest并发连接限制

    .net 的 HttpWebRequest 或者 WebClient 在多线程情况下存在并发连接限制,这个限制在桌面操作系统如 windows xp , windows  7 下默认是2,在服务器操作 ...

  8. HBase的shell命令行界面按退格键(Backspace)无法删除问题

    在HBase的shell命令行界面输入错误项按"退格键"删除,却怎么也删除不了: 解决办法: 第一步,修改SecureCRT的设置参数: 第二步,按"Ctrl+退格键(B ...

  9. 深入理解PHP原理之变量分离/引用

    19 Sep 08 深入理解PHP原理之变量分离/引用(Variables Separation) 作者: Laruence(   ) 本文地址: http://www.laruence.com/20 ...

  10. SpringMVC简单构造restful, 并返回json

    https://my.oschina.net/u/2272916/blog/352297