UVA11427 Expect the Expected 概率dp+全概率公式
题意:小明每晚都玩游戏,每一盘赢的概率都是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+全概率公式的更多相关文章
- UVA - 11427 Expect the Expected (概率dp)
Some mathematical background. This problem asks you to compute the expected value of a random variab ...
- 11427 - Expect the Expected(概率期望)
11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...
- 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+概率)
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...
- UVa11427 Expect the Expected
数学期望 概率递推 每一天的概率都是独立且相同的.可以先推出每天打i盘赢j盘的概率f[i][j] f[i][j]=f[i-1][j]*(1-p) + f[i-1][j-1]*p 输 赢 设此人打一天胜 ...
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- ZOJ3582:Back to the Past(概率DP)
Recently poet Mr. po encountered a serious problem, rumor said some of his early poems are written b ...
随机推荐
- 【总】.NET Core 2.0 详解
ASP.NET Core 认证与授权[7]:动态授权 雨夜朦胧 2017-11-24 11:21 阅读:7063 评论:19 ASP.NET Core 认证与授权[6]:授权策略是怎么执行的? 雨夜朦 ...
- 自定义servlet重写doGet或者doPost方法时,405 method not allowed
自定义servlet public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServlet ...
- 1005 -- I Think I Need a Houseboat
I Think I Need a Houseboat Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 105186 Acc ...
- 2019-8-31-How-to-parse-version-range
title author date CreateTime categories How to parse version range lindexi 2019-08-31 16:55:58 +0800 ...
- 负载均衡实现故障vip自动漂移
环境说明演示vip自动漂移 192.168.237.50 192.168.237.51 vip: 192.168.237.5 keepalived开源软件实现 keepalived可以实现当vip挂的 ...
- 一只青蛙一次可以跳1阶或者2阶,n阶,有多少种到达终点的方式。
前两天面试遇到的一个题,当时没有想清楚,今天想了一下,po出来: # -*-encoding:utf-8-*- import sys end = 0 # 终点 cnt = 0 # 统计组合方式 def ...
- bcpow — 任意精度数字的乘方
bcpow — 任意精度数字的乘方 说明 string bcpow ( string $left_operand , string $right_operand [, int $scale ] ) 左 ...
- 用JavaScript写一个JD放大镜
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- spring接收文件资源
提交请求的contentType为multipart/form-data 图片提交在form中的名称为file 后端接收示例 @RequestMapping("/picture") ...
- 「题解」:$Six$
问题 A: Six 时间限制: 1 Sec 内存限制: 512 MB 题面 题面谢绝公开. 题解 来写一篇正经的题解. 每一个数对于答案的贡献与数本身无关,只与它包含了哪几个质因数有关. 所以考虑二 ...