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 ...
随机推荐
- linux 0.11 源码学习+ IO模型
http://www.cnblogs.com/Fredric-2013/category/696688.html
- careercup-数组和字符串1.7
1.7 编写一个算法,若M*N矩阵中某个元素为0,则将其所在的行与列清零. 类似于leetcode中的 Set Matrix Zeroes C++实现代码: #include<iostream& ...
- Using JAAS Authentication in Java Clients---weblogic document
The following topics are covered in this section: JAAS and WebLogic Server JAAS Authentication Devel ...
- GUI编程笔记(java)10:GUI实现一级菜单
1.首先:菜单组件 MenuBar,Menu,MenuItem 先创建菜单条,再创建菜单,每一个菜单中建立菜单项. 也可以菜单添加到菜单中,作为子菜 ...
- linux vncserver配置
需要使用Linux的远程桌面服务,xmanager之前用过,感觉一般,这次尝试下vnc 我的操作系统是centos7 一服务端 安装VNCServer #yum -y install vnc *vnc ...
- servlet登录
package com.lxr.servlet; import java.io.IOException; import java.io.PrintWriter; import java.sql.Pre ...
- (转)spring ioc原理(看完后大家可以自己写一个spring)
最近,买了本Spring入门书:spring In Action .大致浏览了下感觉还不错.就是入门了点.Manning的书还是不错的,我虽然不像哪些只看Manning书的人那样专注于Manning, ...
- Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏
实现方法: public class SingleTon<T> where T : class, new() { protected SingleTon() { } pri ...
- wcf入门教程
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...
- 【基础】Oracle 表空间和数据文件
多个表空间的优势:1.能够将数据字典与用户数据分离出来,避免由于字典对象和用户对象保存在同一个数据文件中而产生的I/O冲突2.能够将回退数据与用户数据分离出来,避免由于硬盘损坏而导致永久性的数据丢失3 ...