HDU 5781 ATM Mechine (概率dp)(求最优策略期望)
来源:互联网 发布:域名购买后要做什么 编辑:程序博客网 时间:2024/05/18 03:45
ATM Mechine
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 559 Accepted Submission(s): 245
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.
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
Each test case contains two numbers K and W.
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 14 220 3
Sample Output
1.0000002.4000004.523810
Author
ZSTU
Source
2016 Multi-University Training Contest 5
Recommend
wange2014 | We have carefully selected several similar problems for you: 5792 5790 5789 5788 5787
题意:有个人去ATM机里取钱,但是他不知道卡里有多少钱,而且这台ATM机不提供查询余额的功能,他只知道钱的上限 K, 每次他都要取一定的钱 y ,如果他的存款大于等于y,他就得到y钱, 如果取的钱超过了余额,他就会被警告 1 次,求在最优策略下,取的钱上限是 K,警告次数不超过 W 。问你取钱次数期望最小是多少。
题解:E(i,j) :存款的范围是 [0,i] , 还可以被警告 j次的期望值。假如Alice使用的是二分策略,那么在最坏情况下至多被警告⌈log2K⌉ 次。于是W=min(W,15) 就可以了。
这样时间复杂度是
AC代码:
#include<bits/stdc++.h>using namespace std;const double INF = 1e12;double dp[2010][20];double solve(int k, int w){ if(k == 0) return dp[k][w] = 0; if(w == 0) return INF; if(dp[k][w] > 0 ) return dp[k][w]; dp[k][w] = INF; for(int i=1; i<=k; i++) dp[k][w] = min(dp[k][w],(double)(k-i+1)/(k+1)*solve(k-i,w)+(double)i/(k+1)*solve(i-1,w-1)+1); return dp[k][w];}int main(){ int k, w; while(~scanf("%d%d",&k,&w)) { w = min(w,15); printf("%.6lf\n",solve(k,w)); } return 0;}
1 0
- HDU 5781 ATM Mechine (概率dp)(求最优策略期望)
- HDU 5781 ATM Mechine(概率DP求期望)
- HDU 5781 ATM Mechine (概率dp 求期望最小)
- hdu 5781 ATM Mechine 概率(期望)dp
- 【HDU 5781】ATM Mechine(概率DP)
- HDU 5781 ATM Mechine(概率DP)
- [HDU 5781] ATM Mechine (带有最优的期望)
- HDU 5781 ATM Mechine 多校赛 概率dp
- HDU 5781 ATM Mechine (概率DP)
- HDU 5781 ATM Mechine(概率dp)
- Hdu-5781 ATM Mechine(DP)
- HDU 5781 ATM Mechine(dp)
- hdu5781[ATM Mechine] 浅尝期望概率DP
- HDU5781 ATM Mechine (概率dp)
- HDU-5781-ATM Mechine(记忆化搜索+期望)
- HDU 5781 ATM Mechine 16多校5 概率dp
- HDU-5781-ATM Mechine-DP
- HDU 5781 ATM Mechine dp
- [2.0] 函数式编程初探
- SPOJ 4491 PGCD - Primes in GCD Table(莫比乌斯反演)
- kali2.0 U盘安装无法挂载安装光盘
- Qt操作Excel文件 QtXlsxWriter的配置使用说明
- NativeActivity的胶水层android_native_app_glue详解和使用
- HDU 5781 ATM Mechine (概率dp)(求最优策略期望)
- linux环境下mysql的使用
- 我的csdn博客之旅开启啦!
- linux入门
- hive udaf开发入门和运行过程详解
- Java接口详解
- angularjs 中的 $promise
- redis的基本操作
- 杭电ACM 2023 求平均成绩