题目链接

\(Description\)

https://blog.csdn.net/Yukizzz/article/details/52084528

\(Solution\)

首先每一天之间是独立的。

所以设\(f[i][j]\)为前\(i\)天赢了\(j\)局的概率,要满足当前获胜比例始终≤\(p\)。容易得出转移方程。

所以玩完\(n\)局之后获胜比例仍不超过\(p\)的概率为\(Q=\sum_{i=0}^{\frac in\leq p}f[n][i]\)。

设\(E\)为期望玩牌天数。有两种情况:

1.\(Q\)的概率不再玩了,期望为\(Q\times1\);

2.\(1-Q\)的概率第二天接着玩,期望为\((1-Q)\times(E+1)\)。

所以\(E=Q+(1-Q)\times(E+1)\),解得\(E=\frac 1Q\)。

有点迷,但好像也确实是这样。。

  1. #include <cstdio>
  2. #include <algorithm>
  3. const int N=105;
  4. double f[N][N];
  5. void Work(int T)
  6. {
  7. int a,b,n;
  8. scanf("%d/%d%d",&a,&b,&n);
  9. double p=1.0*a/b;
  10. f[0][0]=1;
  11. for(int i=1; i<=n; ++i)
  12. {
  13. f[i][0]=f[i-1][0]*(1-p);
  14. for(int j=1; j<=i; ++j) f[i][j]=0;//!
  15. for(int j=1; j*b<=i*a; ++j)
  16. f[i][j]=f[i-1][j]*(1-p)+f[i-1][j-1]*p;
  17. }
  18. double q=0;
  19. for(int i=0; i*b<=n*a; ++i) q+=f[n][i];
  20. printf("Case #%d: %d\n",T,(int)(1.0/q));//直接.0lf是四舍五入...
  21. }
  22. int main()
  23. {
  24. int T; scanf("%d",&T);
  25. for(int i=1; i<=T; Work(i++));
  26. return 0;
  27. }

UVA.11427.Expect the Expected(期望)的更多相关文章

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

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

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

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

  3. UVA 11427 Expect the Expected (期望)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&pa ...

  4. UVa 11427 Expect the Expected (数学期望 + 概率DP)

    题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...

  5. UVA - 11427 Expect the Expected (概率dp)

    Some mathematical background. This problem asks you to compute the expected value of a random variab ...

  6. UVa 11427 - Expect the Expected

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. UVA 11427 Expect the Expected(DP+概率)

    链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...

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

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

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

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

随机推荐

  1. IEnumerator和IEnumerable详解

    IEnumerator和IEnumerable 从名字常来看,IEnumerator是枚举器的意思,IEnumerable是可枚举的意思. 了解了两个接口代表的含义后,接着看源码: IEnumerat ...

  2. js调试系列: 初识控制台

    写在最开头:其实我以前就在考虑要不要写这个东西,因为这个东西确实不难,但是为什么会有这么多人问,他们问的不是怎么用控制台,而是不知道控制台能干嘛,他们也知道有 console.log 之类的东西,但他 ...

  3. [转载]Supporting OData $inlinecount with the new Web API OData preview package

    http://www.strathweb.com/2012/08/supporting-odata-inlinecount-with-the-new-web-api-odata-preview-pac ...

  4. 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas

    [题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...

  5. (F - 超级英雄Hero HYSBZ - 1191 )匈牙利算法

    题目链接:https://cn.vjudge.net/contest/281037#problem/F 题目大意:中文题目 具体思路:可以看成二分图匹配,寻找最大匹配就可以了,注意当某一个匹配不到的时 ...

  6. ecshop 2.7.x 批量测试

    下面为测试是否存在漏洞的脚本: sub MAIN($url) { use HTTP::UserAgent; my $r = HTTP::Request.new(); $r.uri: $url~'/us ...

  7. Linux内核入门(六)—— __attribute__ 机制【转】

    转自:https://blog.csdn.net/yunsongice/article/details/5538020 GNU C的一大特色(却不被初学者所知)就是__attribute__机制.__ ...

  8. SQL008存储过程总结

    1.如何调用存储过程 DECLARE @Id INT --输入参数 DECLARE @OutPutID INT --输出参数 EXEC [dbo].Order_SellPR @Id,@OutPutID ...

  9. 浅谈js设计模式之迭代器模式

    迭代器模式无非就是循环访问聚合对象中的各个元素.比如 jQuery中的 $.each 函数,其中回调函数中的参数 i 为当前索引, n 为当前元素,代码如下: $.each([1, 2, 3], fu ...

  10. C++ code:动态内存

    C++给我们提供了动态内存分配的new和delete操作.一般而论,new和delete操作多用在内存需求捉摸不定的场合.然而,需要处理的数据,如果变动范围很小,我们可以用STL中通用型的容器来做,大 ...