hdu5781ATM Mechine+数学期望
2016-08-03 14:46
591 查看
Problem Description
Alice is going to take all her savings out of the ATM(Automatic Teller Machine). Alice forget how many deposit she has, and this strange ATM doesn’t support query deposit. The only information Alice knows about her deposit is the upper bound is K RMB(that means Alice’s deposit x is a random integer between 0 and K (inclusively)).
Every time Alice can try to take some money y out of the ATM. if her deposit is not small than y, ATM will give Alice y RMB immediately. But if her deposit is small than y, Alice will receive a warning from the ATM.
If Alice has been warning more then W times, she will be taken away by the police as a thief.
Alice hopes to operate as few times as possible.
As Alice is clever enough, she always take the best strategy.
Please calculate the expectation times that Alice takes all her savings out of the ATM and goes home, and not be taken away by the police.
Input
The input contains multiple test cases.
Each test case contains two numbers K and W.
1≤K,W≤2000
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 1
4 2
20 3
Sample Output
1.000000
2.400000
4.523810
Author
ZSTU
Source
2016 Multi-University Training Contest 5
题目意思:Alice忘记了自己银行里存了多少钱,只记得在[0,k]之间。每次取钱如果余额足够就出钱,否则警告一次,警告超过w次就会把你抓起来,在不想被警察抓起来的前提下,Alice采取最优策略,求期望取钱多少次能知道自己存了多少钱。
官方给出的题解
Alice is going to take all her savings out of the ATM(Automatic Teller Machine). Alice forget how many deposit she has, and this strange ATM doesn’t support query deposit. The only information Alice knows about her deposit is the upper bound is K RMB(that means Alice’s deposit x is a random integer between 0 and K (inclusively)).
Every time Alice can try to take some money y out of the ATM. if her deposit is not small than y, ATM will give Alice y RMB immediately. But if her deposit is small than y, Alice will receive a warning from the ATM.
If Alice has been warning more then W times, she will be taken away by the police as a thief.
Alice hopes to operate as few times as possible.
As Alice is clever enough, she always take the best strategy.
Please calculate the expectation times that Alice takes all her savings out of the ATM and goes home, and not be taken away by the police.
Input
The input contains multiple test cases.
Each test case contains two numbers K and W.
1≤K,W≤2000
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 1
4 2
20 3
Sample Output
1.000000
2.400000
4.523810
Author
ZSTU
Source
2016 Multi-University Training Contest 5
题目意思:Alice忘记了自己银行里存了多少钱,只记得在[0,k]之间。每次取钱如果余额足够就出钱,否则警告一次,警告超过w次就会把你抓起来,在不想被警察抓起来的前提下,Alice采取最优策略,求期望取钱多少次能知道自己存了多少钱。
官方给出的题解
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> #include<vector> using namespace std; #define LL long long #define INF 0x3f3f3f3f const double inf=1e12; double f[2016][15]; //最多的钱,剩余可用的次数 double bank(int m,int w){ if(m==0) return 0; if(w==0) return inf; if(f[m][w]>0) return f[m][w]; double ans=inf; for(int i=1;i<=m;i++){ //枚举实际的钱数 ans=min(ans,bank(i-1,w-1)*i/(m+1)+bank(m-i,w)*(m-i+1)/(m+1)+1); //为什么加1.。考虑的很久,菊苣已解释貌似就知道了。 //试了一次之后,产生了两种步数期望,还要加上我试的这一次。 //orz巨啊。。。 } return f[m][w]=ans; } int main(){ int k,w; fill(f[0],f[0]+2016 * 15,0.0); while(scanf("%d %d",&k,&w)!=EOF){ w=min(w,15);//为什么15呢?因为二分查找2^15>2000 printf("%.6f\n",bank(k,w)); } return 0; }
相关文章推荐
- HDU5723 Abandoned country(最小生成树,数学期望)
- 数学期望与方差E(X) D(X)
- BZOJ 3143 游走 | 数学期望 高斯消元
- Uva12230Crossing Rivers (数学期望)
- BZOJ1076 [SCOI2008]奖励关 【状压dp + 数学期望】
- uva11427(数学概率与期望)
- HDU - 5245 Joyful(数学期望)
- hdu 5419(数学期望)
- BZOJ 1426: 收集邮票 期望DP,数学推导
- hdu 5194 DZY Loves Balls(暴力,数学期望)
- 数学概念——D 期望
- codeforces 268E Playlist(数学期望)
- UPCOJ-5333 - 大佬 - 数学期望
- 关于数学期望的总结
- HDU 4405 Aeroplane chess(概率dp,数学期望)
- CodeForces 453A(数学期望)
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
- hdu 3853(数学期望入门)
- 中台风险分析-数学期望的现实意义
- hdu 4438 Hunters(数学期望)