OI Problems   关于

#zd7g4g. ATM Machine

时间限制:3 s       空间限制:64 MiB       标签: 动态规划 记忆化搜索 HDU 缺题解 

算法难度等级:0       思维难度等级:0       实现难度等级:0


本题来源于:ATM Machine - 2016 Multi-University Training Contest 5

  • 简体中文
  • English

题目描述

一个人去 ATM 机里取钱,但是他不记得卡里有多少钱了,而且这个 ATM 机不提供查询的功能,他知道钱的上限是 KK,每次他都要取一定的钱 yy,如果他的存款余额大于等于 yy,他马上就得到 yy 元钱,如果 yy 超过了余额,他就会被警告 11 次,如果超过 WW 次警告,警察就会过来抓他。求在最优策略下,取钱的期望次数。

输入格式

有多组测试数据,EOF 结束,每组数据一行两个整数 K,WK,W

1K,W20001\leq K,W\leq 2000

输出格式

输出答案,保留 66 位小数。

样例

1 1
1.000000
4 2
2.400000
20 3
4.523810

数据范围与提示

题意补充:取的钱数必须是正整数,要求在保证取完钱和警告次数不超的情况下最小化期望次数。初始卡里的钱数在 [0,K][0,K] 等概率随机。

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 KK RMB(that means Alice's deposit xx is a random integer between 00 and $K4 (inclusively)).

Every time Alice can try to take some money yy out of the ATM. if her deposit is not small than yy, ATM will give Alice yy RMB immediately. But if her deposit is small than yy, Alice will receive a warning from the ATM.

If Alice has been warning more then WW 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 KK and WW.

1K,W20001\leq K,W\leq 2000

Output

For each test case output the answer, rounded to 66 decimal places.

Sample

1 1
4 2
20 3
1.000000
2.400000
4.523810