Uva 11427 Expect the Expected 概率dp 求数学期望
2016-08-08 18:18
603 查看
/* 题目描述:有一个人跟人打牌 , 每局赢的概率是p ,他一晚上最多跟人玩n局,但如果他当前的胜率超过了n,那么 他就会心满意足地去睡觉,如果他的胜率不能超过p , 那么他就会一直跟人打下去直到玩足了n把,一旦玩足 n局胜率还没有超过p,他就会垂头丧气地去睡觉并且今后再也不打牌了,问这个人平均玩牌能玩几晚上 方法:计算玩的晚上数的数学期望,首先要计算出一天内n局后胜率不超过p的概率Q , 则答案为1/Q(可以通过相应 推导证明这一结论),那么问题就是怎么计算一天内胜率不超过p的概率 设dp[i][j]表示在当前胜率不超过p的情况下i局内胜j局的概率 : 那么若 j / i 大于p ,说明当前胜率已经超过p , 则dp[i][j] = 0; 若j / i小于等于p,则dp[i][j] = dp[i-1][j] * (1 - p) + dp[i-1][j-1] * p,含义为胜率不超过p的情况下i-1局内胜了j局 后再输一局的概率加上胜率不超过p的情况下i-1局内胜了j-1局后再胜一局的概率 */ #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define mem(a,x) memset(a , x , sizeof(a)) using namespace std; const int maxn = 105; int n , s , r ; double dp[maxn][maxn]; int main() { int T , kase = 0; scanf("%d",&T); while(T--){ scanf("%d/%d %d",&s ,&r , &n); mem(dp , 0); dp[0][0] = 1; double p = 1.0 * s / r , Q = 0 ; for(int i = 1;i<=n;i++){ dp[i][0] = pow(1 - p , i); for(int j = 1;j<=i;j++){ if(1.0 * j / i <= p ) dp[i][j] = dp[i-1][j] * (1 - p) + dp[i-1][j-1] * p; else dp[i][j] = 0; } } for(int i = 0 ; i<=n ; i++){ if( 1.0 * i / n > p) break; Q += dp [i]; } int ans = 1 / Q; printf("Case #%d: %d\n",++kase,ans); } return 0; }
相关文章推荐
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
- UVA 11427 - Expect the Expected (概率DP 期望)
- UVA 11427 Expect the Expected (概率dp+推公式求期望 详解)
- uva 11427 Expect the Expected 概率dp求期望
- UVA 11427 Expect the Expected(DP+概率)
- 概率DP,记忆化搜索(Expect the Expected,uva 11427)
- UVa 11427 (期望 DP) Expect the Expected
- UVA - 11427 Expect the Expected (DP+概率)
- 11427 - Expect the Expected(概率期望)
- UVA 11427 Expect the Expected【期望】
- UVA 11427 Expect the Expected [概率]
- UVA 11427 - Expect the Expected(概率递推期望)
- UVa11427 - Expect the Expected(概率期望+dp)
- UVA 11427 Expect the Expected (期望)
- uva 11427 - Expect the Expected(概率)
- uva 11427 - Expect the Expected(概率)
- UVA 11427 - Expect the Expected(概率递归预期)
- [UVA11427] Expect the Expected && 数学期望
- Uva 11427 Expect the Expected
- UVa11427 Expect the Expected