题目传送门

题意:小明每晚都玩游戏,每一盘赢的概率都是p,如果第一盘就赢了,那么就去睡觉,第二天继续玩;否则继续玩,玩到赢的比例大于p才去睡;如果一直玩了n盘还没完成,就再也不玩了;问他玩游戏天数的期望;

思路:由于每次玩游戏,每天玩游戏都是独立重复试验,所以可以考虑一天玩游戏,玩不到p的概率(p都玩不到?)。

  设$dp[i][j]$表示玩了i次游戏,获胜j次,并且过程中期望都不会超过p的概率。

  则显然有:$dp[i][j]=dp[i-1][j]*(1-p)+dp[i-1][j-1]*p$。

   需要注意的是,我们必须保证过程中游戏分数的期望不会超过p,所以每一个状态都必须是$\frac{j}{i}<p$,而且由于是T组样例,记得每次都要清空dp数组,否则上一次的答案可能会影响当前这次(上一次不合法的状态到了这一次变成合法状态了,被统计入了答案)。

  然后求出总的失败概率,设概率为q,期望天数为e。

  由全概率公式可得$e=q*1+(1-q)*(e+1)$

  移项得$e=\frac {1}{q}$

#pragma GCC optimize (2)
#pragma G++ optimize (2)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,b,a) for(int i=b;i>=a;--i)
#define clr(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pii pair<int,int >
using namespace std;
typedef long long ll;
ll rd()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int maxn=;
double dp[maxn][maxn];
int x,y,n;
int main(){
int T,cat=;
cin>>T;
while(T--){
scanf("%d/%d%d",&x,&y,&n);
double p=(double)x/y;
clr(dp,);
dp[][]=;
rep(i,,n){
for(int j=;j*y<=i*x;j++){
dp[i][j]=dp[i-][j]*(-p);
if(j)dp[i][j]+=dp[i-][j-]*p;
}
}
double res=;
for(int i=;i*y<=n*x;i++){
res+=dp[(int)n][i];
}
printf("Case #%d: %d\n",cat++,(int)(/res));
}
}

UVA11427 Expect the Expected 概率dp+全概率公式的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. UVa11427 Expect the Expected

    数学期望 概率递推 每一天的概率都是独立且相同的.可以先推出每天打i盘赢j盘的概率f[i][j] f[i][j]=f[i-1][j]*(1-p) + f[i-1][j-1]*p 输 赢 设此人打一天胜 ...

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

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

  8. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  9. ZOJ3582:Back to the Past(概率DP)

    Recently poet Mr. po encountered a serious problem, rumor said some of his early poems are written b ...

随机推荐

  1. Arcpy 将要素类添加到当前工作窗口(内容列表)

    test1layer=arcpy.mapping.Layer( folder+"\\"+"result.shp") mxd = arcpy.mapping.Ma ...

  2. Linux下svn更新含有中文名称的库无法更新问题

    Linux下更新含有中文名称的库文件时,出现如下提示: SVN Error: Can't convert string from native encoding to 'UTF-8' 通过google ...

  3. ionic3 多级联动城市选择插件 ion-multi-picker

    1.效果演示 2.npm安装扩展包依赖  ion-multi-picker 组件 npm install ion-multi-picker --save 3.在app.module.ts中导入插件模块 ...

  4. AJAX 向后台发送带 List 集合的对象(转)

    var school = {};school.name = '清华大学';school.address = "北京";//此处使用的是 easyui 插件来获取数据var rows ...

  5. HashMap循环

    1. Map的四种遍历方式下面只是简单介绍各种遍历示例(以HashMap为例),各自优劣会在本文后面进行分析给出结论. (1) for each map.entrySet()   Java   1 2 ...

  6. P4151 [WC2011]最大XOR和路径 线性基

    题目传送门 题意:给出一幅无向图,求1到n的所有路径中最大异或和,一条边可以被重复经过. 思路: 参考了大佬的博客 #pragma GCC optimize (2) #pragma G++ optim ...

  7. shell脚本之用户管理

    #!/usr/bin/env bash ############################### # 脚本名称 : userManager.sh # # 脚本功能 : 账号管理 # # 脚本参数 ...

  8. leetcode-13双周赛-1256-加密数字

    题目描述:编码 方法一: class Solution(object): def encode(self, n): if n == 0: return "" n -= 1 A = ...

  9. 2019 ACM/ICPC Asia Regional shanxia D Miku and Generals (二分图黑白染色+01背包)

    Miku is matchless in the world!” As everyone knows, Nakano Miku is interested in Japanese generals, ...

  10. css3 动画+动画库

    css3 动画 实现原理 1.transition 过渡:https://www.runoob.com/cssref/css3-pr-transition.html 语法:( transition的 ...