# 概率DP_____ATM Mechine( hdu 5781 2016多校第五场)

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.
1K,W2000

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

dp[i][j] = min(dp[i][j] , dp[i-k][j]+dp[k-1][j-1]+1)然而时间复杂度为O(K^2M)但是仔细观察我们可以知道。爱丽丝是聪明的也就是采用二分的方式是出现警告最多的方式。也就是LogK <= 15. 所以最多只会出现15次警告。那么复杂度就降下来了。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
double dp[2010][16];

double dfs(int w,int c)
{
if(dp[w][c] != -1) return dp[w][c];
if(w == 0) return 0;
if( c == 0) return 1e9;
double ans = 1e9;
double k = 1.0/(1.0+w);
for(int i = 1 ; i <= w ; i ++ )
ans = min(ans,i*k*dfs(i-1,c-1)+(w+1-i)*k*dfs(w-i,c)+1);
return dp[w][c]=ans;
}
int main()
{

int i,j,k,w;
for (i=0;i<2010;i++)
for (j=0;j<16;j++) dp[i][j]=-1;
while (scanf("%d%d", &k, &w)!=EOF) {
w=min(w,15);printf("%.6f\n", dfs(k,w));
}
return 0;
}


#### hdu4345 Permutation-----多校联合五

2012-08-08 08:43:36

#### HDU 6086 Rikka with String （AC 自动机+状压 dp, 2017 Multi-Univ Training Contest 5）

2017-08-13 10:24:16

#### hdu 6086 -- Rikka with String(AC自动机 + 状压DP)

2017-08-22 12:51:12

#### hdu 6086 Rikka with String ac自动机+dp

2017-08-09 12:29:15

#### HDU - 5202 - Rikka with string （DFS）

2015-04-11 23:45:19

#### 2016HDU多校联赛-HDU-5723-Abandoned country（最小生成树 邻接表DFS）

2016-07-20 10:05:21

#### 2016多校第五场 1001 HDU 5781 DP

2016-08-03 11:22:02

#### 2016HDU多校赛第1场

2016-07-20 11:30:12

#### HDU5810（2016多校第七场）——Balls and Boxes（组合数学，概率）

2016-08-09 17:51:38

#### 2016 多校第一场 hdu 5723(最小生成树＋dfs)

2016-07-20 22:24:32