HDU 5781 ATM Mechine(概率DP求期望)
来源:互联网 发布:hbuilder下载 mac 编辑:程序博客网 时间:2024/04/30 12:55
传送门
ATM Mechine
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 376 Accepted Submission(s): 165
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 1
4 2
20 3
Sample Output
1.000000
2.400000
4.523810
题目大意:
一个人去ATM机里取钱,但是他不知道卡里有多少钱,而且这个ATM机不提供查询余额的功能,他只知道钱的上限
解题思路:
这样时间复杂度是
/**2016 - 08 - 03 上午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const double INF = 1e12;const int MAXN = 2e3+5;const int MOD = 1e9+7;const double eps = 1e-7;double dp[MAXN][20];double Solve(int k, int w){ if(k == 0) return dp[k][w] = 0; if(w == 0) return INF; if(dp[k][w] > eps) 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,12); printf("%.6lf\n",Solve(k,w)); } return 0;}
0 1
- 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 多校赛 概率dp
- HDU 5781 ATM Mechine (概率DP)
- HDU 5781 ATM Mechine(概率dp)
- hdu5781[ATM Mechine] 浅尝期望概率DP
- Hdu-5781 ATM Mechine(DP)
- HDU 5781 ATM Mechine(dp)
- HDU 5781 ATM Mechine 16多校5 概率dp
- HDU-5781-ATM Mechine-DP
- HDU 5781 ATM Mechine dp
- [HDU 5781] ATM Mechine (带有最优的期望)
- HDU-5781-ATM Mechine(记忆化搜索+期望)
- HDU5781 ATM Mechine (概率dp)
- 人生不应该让自己感到遗憾
- 蓝牙之五-bludroid协议栈和厂商代码的交互
- jquery的.fn.extend使用方法
- python番外(1)——matplotlib中文显示问题
- bzoj2768(最小割,二者取其一式问题)
- HDU 5781 ATM Mechine(概率DP求期望)
- ReactiveCocoa信号使用方法
- 解MPU6050,用STM32读取原始数据,并相互融合算出俯仰角、翻滚角、偏航角
- POJ1815
- MySql 5.7.13解压版安装和出现的一些问题
- Android应用横竖屏切换的两种方式,从表现上看最大的区别
- php 内存
- HDU 5788 Level Up
- 缓存技术之Ehcache(5)对象缓存