Uva_11427 Expect the Expected
题意:
你玩纸牌, 如果当天晚上你赢的局数比例 大于 p, 就去睡觉, 第二天继续。 如果小于等于p, 就去睡觉, 并且以后都不玩了。
每晚最多玩n局, 每局赢的概率为p , 求玩的天数的期望。
思路:
设dp[i][j] 为玩了i局, 赢了j局的概率。
则期望E = sigma(i = 0, 1, 2, 3, 4, ........)x *dp[n][i]。
为无穷级数。
先来求dp[i][j]。
dp[i]][j] = dp[i-1][j] * (1 - p) = dp[i-1][j-1] * p。
化简得:E = 1 / sum(dp[n][i])
代码如下:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAXN 110
#define MOD 1000000007
#define eps 1e-6
double p;
int a, b;
int n;
double dp[MAXN][MAXN];
void init()
{
memset(dp, , sizeof(dp));
dp[][] = ;
dp[][] = ; for(int i = ; i <= n; i ++)
{
dp[i][] = dp[i-][] * (1.0 - p);
for(int j = ; j * b <= a * i; j ++)
dp[i][j] = dp[i-][j] * (1.0 - p) + dp[i-][j-] * p;
}
} int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
scanf("%d/%d %d", &a, &b, &n);
p = (double)a / (double)b;
init();
double ans = 0.0;
for(int i = ; i * b <= n * a; i ++)
ans += dp[n][i];
ans = / ans;
printf("Case #%d: %d\n", ++ kcase, (int)ans);
}
return ;
}
Uva_11427 Expect the Expected的更多相关文章
- 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)
Some mathematical background. This problem asks you to compute the expected value of a random variab ...
- 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
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11427 Expect the Expected (期望)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&pa ...
- UVa 11427 (期望 DP) Expect the Expected
设d(i, j)表示前i局每局获胜的比例均不超过p,且前i局共获胜j局的概率. d(i, j) = d(i-1, j) * (1-p) + d(i-1, j-1) * p 则只玩一天就就不再玩的概率Q ...
- UVA 11427 Expect the Expected(DP+概率)
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...
随机推荐
- BA - 读书雷达10本必读书
https://www.douban.com/doulist/43172796/ 用户故事与敏捷方法 入门篇之一: “是每个ThoughtWorks BA都读的经典入门书籍,详细介绍了用户故事及实用操 ...
- Java反射_JDBC操作数据
</pre><p>使用反射 来操作 这里是练习反射的使用</p><p>链接数据库工具类</p><p><pre name= ...
- 通过Navicat for MySQL远程连接的时候报错mysql 1130的解决方法
在用本地的navicat连接服务器的mysql数据库时候出现下面的问题: 解决的方法: 解决方法: 1.改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhos ...
- ContentProvider与ContentResolver使用
例如以下内容为从网络转载: 使用ContentProvider共享数据: 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就能够向其它应用共享其数据.虽然使用其它方 ...
- [D3] 5 .rangeBands
# d3.max ```js var xScale = d3.scale.ordinal() .domain(dataset) .rangeBands([0,w],0.3, 0.1);``` ### ...
- UVA - 10239 The Book-shelver's Problem
Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time ...
- 网站优化的经验和技巧--精简高效的C#
对大型网站,技术涉及面非常广,对硬件,软件,编程语言,Web Service,防火墙等等有很高要求. 面对大量用户,高并发请求,可以使用高性能服务器,高性能编程语言,高性能数据库,加大带宽等,这 ...
- 【Android】isEmpty()
对字符串进行非空判断,可以一次性进行两种空值的判断.当传入的字符串等于null或者等于空字符串的时候这个方法都会返回true,从而不需要单独去判断这两种空值,再利用逻辑运算符连接起来.
- RedHat7 SELinux
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统.NSA是在Linux社区的帮助下开发了一种 ...
- HDU-1012(水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1012 分析:就按题目给的公式一步步输出就行了. #include<stdio.h> #include ...