uva 11427 - Expect the Expected(概率)
来源:互联网 发布:送女朋友生日礼物知乎 编辑:程序博客网 时间:2024/06/05 16:13
题目链接:uva 11427 - Expect the Expected
题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结束游戏,若n局后仍没有,就会不开心,然后以后再也不完牌,问说你最多会玩多少个晚上。
解题思路:当j/i ≤ p时有dp(i-1,j) (1-p) + dp(i-1, j-1)p,其他dp(i,j) = 0.Q=∑d(n,i)
列出数学期望公式:
EX=Q+2Q(1−Q)+3Q(1−Q)2+…
s=EXQ=1+2(1−Q)+3(1−Q)2+…
(1−Q)∗s=(1−Q)+2(1−Q)2+3(1−Q)3+…
EX=Qs=1+(1−Q)+(1−Q)2+(1−Q)3…
为等比数列,根据等比数列求和公式,n趋近无穷大是为1/Q
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 105;double dp[maxn][maxn];int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { int a, b, n; scanf("%d/%d%d", &a, &b, &n); double p = (double)a / b; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; dp[0][1] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j * b <= a * i; j++) { dp[i][j] = dp[i-1][j] * (1-p); if (j) dp[i][j] += dp[i-1][j-1] * p; } } double q = 0; for (int i = 0; i * b <= a * n; i++) q += dp[n][i]; printf("Case #%d: %d\n", kcas, (int)(1/q)); } return 0;}
1 0
- uva 11427 - Expect the Expected(概率)
- uva 11427 Expect the Expected 概率dp求期望
- UVA 11427 - Expect the Expected(概率递推期望)
- UVA - 11427 Expect the Expected (DP+概率)
- UVA 11427 - Expect the Expected (概率DP 期望)
- UVA 11427 Expect the Expected 概率与期望
- Uva 11427 Expect the Expected 概率dp 求数学期望
- UVA 11427 Expect the Expected
- UVA 11427 - Expect the Expected
- [UVA 11427] Expect the Expected
- UVA 11427 Expect the Expected
- Uva 11427 Expect the Expected
- UVa 11427 Expect the Expected
- UVA 11427 Expect the Expected (概率dp+推公式求期望 详解)
- 概率DP,记忆化搜索(Expect the Expected,uva 11427)
- UVA 11427 Expect the Expected【期望】
- Expect the Expected(dp+概率)
- Expect the Expected UVA11427
- swif字典之dict
- java枚举类型enum的使用
- 反射01
- robots.txt测试工具
- 《天空之城》电影短评
- uva 11427 - Expect the Expected(概率)
- 百度员工离职总结:如何做个好员工
- 正则表达式——密码规则匹配
- KMP算法
- C++之桟的应用---括号匹配
- 给我如果
- unity3d粒子系统属性参数翻译详解
- 恶徒哈尔v
- Reverse Words in a String 翻转字符串