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 ...
随机推荐
- UVA 297 Quadtrees(四叉树建树、合并与遍历)
<span style="font-size: 18pt; font-family: Arial, Helvetica, sans-serif; background-color: r ...
- RichTextBox选中文本时往自己的其他的位置实现拖拽
private void Form1_Load(object sender, EventArgs e) { richTextBox1.AllowDrop = true; richTextB ...
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
主要的代码是红色区域,HTML5获取本地文件对象并进行操作 //给上传按钮添加点击事件 $(".myappTXTUploadBtn").click(function(){ var ...
- [Redux] Normalizing the State Shape
We will learn how to normalize the state shape to ensure data consistency that is important in real- ...
- [Redux] Colocating Selectors with Reducers
We will learn how to encapsulate the knowledge about the state shape in the reducer files, so that t ...
- gdb调试运行时的程序小技巧
使用gdb调试运行时的程序小技巧 标签: 未分类 gdb pstack | 发表时间:2012-10-15 04:32 | 作者:士豪 分享到: 出处:http://rdc.taobao.com/bl ...
- display_errors & error_reporting(php调试安全)
这两个选项对应的值即都可以在php.ini文件中设置,也都可以在php代码中使用相应的函数来设置. 在php.ini文件中的设置如下:
- 获取DLL的文件路径以及调用DLL的文件路径
如何在DLL中,获取DLL本身的路径以及调用DLL的文件的路径呢?主要通过GetModuleFileName(HMODULEhModule,LPTSTR lpFilename,DWORD nSize) ...
- linux tar 压缩解压缩
解压 .tar.bz tar zxvf file.tar.gz .tar.gz2 tar jxvf file.tar.bz2 .bz gzip -d file.bz .gz2 bzip2 -d fil ...
- JS获取图片上传地址
function getObjectURL(file) { var url = null ; if (window.createObjectURL!=undefined) { // basic url ...