hdu 5781 ATM Mechine
来源:互联网 发布:mac bsd 编辑:程序博客网 时间:2024/05/27 08:13
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现场,没写出来。后来看题解补的;
因为当时没太理解题意;
题意:
爱丽丝去取钱,她忘了他具体有多少钱,但是知道最多有多少K;
他可以尝试着去取钱,如果取的钱小于等于他存的钱数,就取成功,否则被警告一次。
当他被警告超过W次后,她将会被警察带走。
问她不被警察带走且能取完钱的期望。
当然当取1元取不出时,说明钱全部取出;
题解:
E(i,j):存款的范围是[0,i],还可以被警告j次的期望值。
E(i,j) = maxk=1ii+1i−k+1∗E(i−k,j)+i+1k∗E(k−1,j−1)+1 这样时间复杂度是O(K2W)的。 假如Alice使用的是二分策略,那么在最坏情况下至多被警告⌈log2K⌉ 次。 于是W:=min(W,15)就可以了。
然后clar有人问y是不是要整数。由于存款是整数,你取小数的钱没有任何意义啊。
就是算出来所有值可能;
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <stack>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define N 200005#define mod 1000000007const double INF=999999999;double dp[2010][20];double solve(int k,int w){ if(k==0) return 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 k,w;int main(){ while(~scanf("%d%d",&k,&w)) { w=min(w,11); printf("%0.6lf\n",solve(k,w)); } return 0;}
0 0
- HDU 5781 ATM Mechine
- hdu 5781 ATM Mechine
- 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)
- 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
- HDOJ 5781 ATM Mechine
- [HDU 5781] ATM Mechine (带有最优的期望)
- HDU 5781--ATM Mechine(记忆化搜索+暴力)
- HDU 5781 ATM Mechine(概率DP求期望)
- ue4中的像素卡通渲染偏色问题和色彩校正理论
- tjut 2830
- ueditor使用_2_配置修改contextpath
- 在 Mac 下Django 使用PostgreSQL 出现的 No module named psycopg2
- 技术分享一览
- hdu 5781 ATM Mechine
- [译] 移动应用设计新趋势
- 统计回文
- Codeforces #366(div 2)
- iOS设计模式——委托(delegate)
- 你必须知道的 34 个简单实用的 Ubuntu 快捷键
- Android开发拔号器案例01
- python离线获取帮助
- ++i 与 i++的区别在哪里?