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. MTK Camera 开机启动流程(转载)

    一.MTK平台Camera框架 MTK平台的Camera的架构见下图, 这里主要介绍kernel部分和HAL层部分. 1.Kernel 部分主要有两块: 1.1.image sensordriver, ...

  2. Python学习(16)File(文件)方法

    Python File(文件) 方法 file 对象使用 open 函数来创建,下表列出了 file 对象常用的函数: 序号 方法及描述 1 file.close() 关闭文件.关闭后文件不能再进行读 ...

  3. 【linux命令】:查看当前登录用户的信息,本文介绍3种方法

    作为系统管理员,你可能经常会(在某个时候)需要查看系统中有哪些用户正在活动.有些时候,你甚至需要知道他(她)们正在做什么.本文为我们总结了4种查看系统用户信息(通过编号(ID))的方法. 1. 使用w ...

  4. 转:The Knuth-Morris-Pratt Algorithm in my own words

    The Knuth-Morris-Pratt Algorithm in my own words For the past few days, I’ve been reading various ex ...

  5. SDL2.0的VS开发环境搭建

    SDL2.0的VS开发环境搭建 [前言] 我是用的是VS2012,VS的版本应该大致一样. [开发环境搭建] >>>SDL2.0开发环境配置:1.从www.libsdl.org 下载 ...

  6. Vbs脚本经典教材(转)

    Vbs脚本经典教材(最全的资料还是MSDN) —为什么要使用Vbs? 在Windows中,学习计算机操作也许很简单,但是很多计算机工作是重复性劳动,例如你每周也许需要对一些计算机文件进行复制.粘贴.改 ...

  7. WCF配置详解

    前面一篇文章<WCF 学习总结1 -- 简单实例> 一股脑儿展示了几种WCF部署方式,其中配置文件(App.config/Web.config)都是IDE自动生成,省去了我们不少功夫.现在 ...

  8. xcode6 framework missing submodule xxx 警告

    xcode6 framework missing submodule xxx 警告 从xcode6开始,iOS可以直接创建生成framework了 如: 创建 framework 项目,TFKit.f ...

  9. 使用XIB实现一个简单view

    技术处女贴 欢迎来探讨 转帖请注明出处 http://www.cnblogs.com/andy-zhou/p/4962135.html 微信: @Andy 1. AppDelegate AppDele ...

  10. 元素过滤器(Element Filters)

    元素过滤器可以同选择器一起使用, 从一堆候选元素中进行筛选.它们当前仅使用于’name’元素选择器.过滤器看起来更像是选择器,也就是:filterType=argument所支持的元素过滤器为:val ...