设d(i, j)表示前i局每局获胜的比例均不超过p,且前i局共获胜j局的概率。

d(i, j) = d(i-1, j) * (1-p) + d(i-1, j-1) * p

则只玩一天就就不再玩的概率Q = sum{d(n, i) | 0 ≤ i ≤ p*n}

那么期望为

这是一个无穷级数,可以用高数的一些知识来解决。

另1-Q = t

将1-Q带入t,并将左边的Q乘过去得:

书上还介绍了一种更简单的方法,假设所求期望为e

第一天玩完就去睡觉,概率为Q,期望为1;第一天玩得高高兴兴,概率为1-Q,期望为1+e

于是有等式:e = Q + (1-Q)(1+e)

 #include <cstdio>
#include <cstring>
const int maxn = + ; double d[maxn][maxn]; int main()
{
//freopen("in.txt", "r", stdin); int T;
scanf("%d", &T);
for(int kase = ; kase <= T; kase++)
{
int n, a, b;
scanf("%d/%d%d", &a, &b, &n);
double p = (double)a / b;
memset(d, , sizeof(d));
d[][] = ; d[][] = ;
for(int i = ; i <= n; i++)
for(int j = ; j*b <= a*i; j++)
{
d[i][j] = d[i-][j]*(-p);
if(j) d[i][j] += d[i-][j-]*p;
} double Q = ;
for(int i = ; i*b <= a*n; i++) Q += d[n][i];
printf("Case #%d: %d\n", kase, (int)(/Q));
} return ;
}

代码君

UVa 11427 (期望 DP) Expect the Expected的更多相关文章

  1. UVA 11427 (概率DP+期望)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...

  2. UVa 11762 (期望 DP) Race to 1

    设f(x)表示x转移到1需要的次数的期望,p(x)为不超过x的素数的个数,其中能整除x的有g(x)个 则有(1-g(x)/p(x))的概率下一步还是转移到x,剩下的情况各有1/p(x)的概率转移到x/ ...

  3. Uva 11600 期望DP

    题意:n个城市,相互可达(有n(n-1)/2条边),其中有一些道路上面有妖怪,现在,从1号城市出发,随机挑取一个城市走去,这个道路上的妖怪就会被消灭,求: 在平均情况下,需要走多少步,使得任意两个城市 ...

  4. UVA 11427 - Expect the Expected(概率递归预期)

    UVA 11427 - Expect the Expected 题目链接 题意:玩一个游戏.赢的概率p,一个晚上能玩n盘,假设n盘都没赢到总赢的盘数比例大于等于p.以后都不再玩了,假设有到p就结束 思 ...

  5. uva 11427 - Expect the Expected(概率)

    题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...

  6. 11427 - Expect the Expected(概率期望)

    11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...

  7. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  8. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  9. 【HDU3853】LOOPS [期望DP]

    LOOPS Time Limit: 5 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description Akemi Homura is a ...

随机推荐

  1. CSDN——【低调的草原狼】——Ext4.2学习目录整理

    最近在研究ExtJS,发现CSDN中有个博客中一系列文档非常优秀,但是没有对目录进行整理,在此稍作整理,也为以后自己研究打下一个基础: 原文作者:低调的草原狼 目录:     1.ExtJS4.2学习 ...

  2. MySQL主从关系设置(转)

    来源:LAMP兄弟连 作者:李恺 http://***/php/bencandy.php?fid=70&id=635 要做MySQL主从关系的设置,那么就得有两台MySQL主机.所以在开始之前 ...

  3. 【.Net--资料】

    1.http://msdn.microsoft.com/zh-cn/dn338450 2..NET Technology Guidance http://www.microsoft.com/net/n ...

  4. MonoBehaviour.StopCoroutine

    MonoBehaviour.StopCoroutine Description Stops all coroutines named methodName running on this behavi ...

  5. Lua print on the same line

    In Pascal, I have write and writeln. Apparently Lua's print is similar to writeln of Pascal. Do we h ...

  6. IOS NSPredicate 查询、搜索

    简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取. 最常用到的函数 + (NSPredicate *)predicateWith ...

  7. 查杀linux线程指令

      工作中重启环境时常常出现内存溢出等等问题,往往需要查杀进程来帮助重启成功,下面就查杀线程的详细指令做下总结:   1.查找需要kill掉的线程: ps -elf|grep [线程关键信息] 比如: ...

  8. Java 编译错误:缺少返回语句

    示例: import java.util.*; import java.io.*; public class tt { public static void main(String[] args) { ...

  9. *[codility]MissingInteger

    今天开始刷刷codility上respectable的题目,难度适中. https://codility.com/demo/take-sample-test/missing_integer 本题是找出 ...

  10. java:内部类与外部类的区别和联系

    注意事项一:在内部类中可以随意使用外部类的成员方法以及成员变量. 众所周知,在定义成员方法或者成员变量的时候,可以给其加上一些权限的修饰词,以防止其他类的访问.如在成员变量或者成员方法前面,加上Pri ...