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 ...
随机推荐
- JSP&Servlet学习手册
JSP&Servlet学习手册 沙琪玛 书 目录 JSP 指令... 3 书写方式... 3 指令列表... 3 JSP 内置对象... 3 内置对象特点... 3 常用内置对象... 3 o ...
- LeetCode153:Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- Material Design之TextInputLayout、Snackbar的使用
这两个控件也是Google在2015 I/O大会上公布的Design Library包下的控件,使用比較简单,就放在一起讲了,但有的地方也是须要特别注意一下. TextInputLayout Text ...
- FolderBrowserDialog
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDial ...
- NuGet的使用心得
前言 上星期发布了NuGet的使用和服务搭建后,同时NuGet在部门里也使用了起来.经过这些天的使用,总结了些小技巧和注意点,希望和大家分享下. 问题提出 使用了NuGet的朋友们估计都知道,在签入代 ...
- swift Array 数组
// // main.Swift // swift数组 // // Created by zhangbiao on 14-6-15. // Copyright (c) 2014年 理想. Al ...
- 256MB小内存MySQL配置优化
[client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mys ...
- iBATIS缓存cacheModel属性浅析
iBATIS缓存cacheModel属性的应用使得在Mapped Statement中缓存常用的数据,那么本文将会给你介绍iBATIS缓存cacheModel属性的信息. AD:2013云计算架构师峰 ...
- 如何写类库方法、属性等的注释,才能在其他地方调用dll文件时,在代码里出现智能提示?
我的本意是想整理下以往写过的代码库,给自己的代码增加复用性.一段时间后,可能自己对写过的代码是什么含义会忘掉,或者别人看自己的代码, 增加可懂性的考虑,决定要添加注释.(好像语句不通:)可是发现,在其 ...
- 原生与jqueryDOM
总结与复习原生与jquery的DOM操作. 获取元素节点: $(".class") $("#id") $(".class div") $(& ...