Some mathematical background. This problem asks you to compute the expected value of a random
variable. If you haven't seen those before, the simple denitions are as follows. A random variable is a
variable that can have one of several values, each with a certain probability. The probabilities of each
possible value are positive and add up to one. The expected value of a random variable is simply the
sum of all its possible values, each multiplied by the corresponding probability. (There are some more
complicated, more general denitions, but you won't need them now.) For example, the value of a fair,
6-sided die is a random variable that has 6 possible values (from 1 to 6), each with a probability of 1/6.
Its expected value is 1=6 + 2=6 + : : : + 6=6 = 3:5. Now the problem.
I like to play solitaire. Each time I play a game, I have probability p of solving it and probability
(1 .. p) of failing. The game keeps statistics of all my games { what percentage of games I have won.
If I simply keep playing for a long time, this percentage will always hover somewhere around p 100%.
But I want more.
Here is my plan. Every day, I will play a game of solitaire. If I win, I'll go to sleep happy until
the next day. If I lose, I'll keep playing until the fraction of games I have won today becomes larger
than p. At this point, I'll declare victory and go to sleep. As you can see, at the end of each day, I'm
guaranteed to always keep my statistics above the expected p 100%. I will have beaten mathematics!
If your intuition is telling you that something here must break, then you are right. I can't keep
doing this forever because there is a limit on the number of games I can play in one day. Let's say that
I can play at most n games in one day. How many days can I expect to be able to continue with my
clever plan before it fails? Note that the answer is always at least 1 because it takes me a whole day
of playing to reach a failure.
Input
The first line of input gives the number of cases, N. N test cases follow. Each one is a line containing
p (as a fraction) and n.
1 < N < 3000, 0 < p < 1,
The denominator of p will be at most 1000,
1 < n < 100.
Output
For each test case, print a line of the form `Case #x: y', where y is the expected number of days,
rounded down to the nearest integer. The answer will always be at most 1000 and will never be within
0.001 of a round-off error case.
Sample Input
4
1/2 1
1/2 2
0/1 10
1/2 3
Sample Output
Case #1: 2
Case #2: 2
Case #3: 1
Case #4: 2

题意:

有一个人,每天最多玩牌n次,每次获胜概率为p,如果今天胜率大于p,他就会去睡觉,如果玩了k把之后,胜率还是没有大于p,那他就会戒掉这个游戏,问他玩这个游戏天数的期望。(向下取整)

思路:

dp[i][j]表示第i天玩到第j把,胜率小于p的概率。

设Q=∑d(n,i)(i/n<p)

Ex=1/Q

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
double dp[][];
int main()
{
// ios::sync_with_stdio(false);
freopen("in.txt","r",stdin); int cases=;
int T;
scanf("%d",&T);
while (T--){
int p1,p2;
scanf("%d/%d",&p1,&p2);
double p=1.0*p1/p2;
int n;
scanf("%d",&n); dp[][]=;
// fuck(p)
for(int i=;i<=n;i++){
dp[i][]=pow(-p,i);
for(int j=;j<=n;j++){
if(p1*i<p2*j){ break;}
dp[i][j]=dp[i-][j-]*p+dp[i-][j]*(-p);
}
}
double q=;
for(int i=;i<=n;i++){
if(1.0*i/n<=p){
q+=dp[n][i];
// fuck(dp[n][i])
}
}
int ans=1.0/q;
printf("Case #%d: %d\n",++cases,ans); }
return ;
}

                           

UVA - 11427 Expect the Expected (概率dp)的更多相关文章

  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(DP+概率)

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

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

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

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

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

  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 (期望)

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

  8. UVA11427 Expect the Expected 概率dp+全概率公式

    题目传送门 题意:小明每晚都玩游戏,每一盘赢的概率都是p,如果第一盘就赢了,那么就去睡觉,第二天继续玩:否则继续玩,玩到赢的比例大于p才去睡:如果一直玩了n盘还没完成,就再也不玩了:问他玩游戏天数的期 ...

  9. UVA.11427.Expect the Expected(期望)

    题目链接 \(Description\) https://blog.csdn.net/Yukizzz/article/details/52084528 \(Solution\) 首先每一天之间是独立的 ...

随机推荐

  1. webstorm 2018.2.3 cmd+w无法关闭文件

  2. Jinja2用法总结

    Jinja2用法总结   一:渲染模版 要渲染一个模板,通过render_template方法即可. @app.route('/about/') def about(): # return rende ...

  3. 【设计模式】原型模式 Pototype Pattern

    前面讲了创建一个对象实例的方法单例模式Singleton Pattern, 创造多个产品的工厂模式(简单工厂模式 Simple Factory Pattern, 工厂方法模式 FactoryMothe ...

  4. Android为TV端助力 EventBus出现has no public methods called onEvent的问题

    Caused by: de.greenrobot.event.EventBusException: Subscriber class com.hhzt.iptv.lvb_w.socket.MyMsgS ...

  5. Python-函数小结

    原文出处,如有侵权,请联系删除. 用户自定义.py文件 如果你已经把my_abs()的函数定义保存为abstest.py文件了,那么,可以在该文件的当前目录下启动Python解释器,用from abs ...

  6. 好代码是管出来的——.Net Core中的单元测试与代码覆盖率

    测试对于软件来说,是保证其质量的一个重要过程,而测试又分为很多种,单元测试.集成测试.系统测试.压力测试等等,不同的测试的测试粒度和测试目标也不同,如单元测试关注每一行代码,集成测试关注的是多个模块是 ...

  7. 『cURL』curl: (6) Could not resolve host无法解析主机地址

    最近在学数据挖掘时,获取数据有两种途径: 开放数据,可以直接使用和存储的数据: 网络数据,通过爬虫或云市场api(付费或免费)获取数据 我通过教程,在阿里云购买一个天气数据api,尝试使用cURL获取 ...

  8. 逆向-攻防世界-logmein

    iDA载入程序,shift+F12查看关键字符串,找到双击来到所在地址,进入函数 然后进入主函数, 经过分析,可以得出:输入的字符要等于  经过处理的v7和v8的异或.v8很明显,但是v7是怎么回事呢 ...

  9. EntityFramework Core 2.1重新梳理系列属性映射(一)

    前言 满血复活啦,大概有三个月的时间没更新博客了,关于EF Core最新进展这三个月也没怎么去看,不知现阶段有何变化没,本文将以EF Core 2.1稳定版本作为重新梳理系列,希望对看本文的你有所帮助 ...

  10. jeecg入门操作—一对多表单开发

    一.创建主表 创建订单主表(torder_main)  二.创建附表客户信息表(torder_customer) 设置附表页面外键不可见 设置附表外键  三.创建附表机票 信息表(torder_tic ...