题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5781

ATM Mechine

Time Limit: 6000/3000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#### 问题描述
> 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.
#### 输入
> The input contains multiple test cases.
> Each test case contains two numbers K and W.
1≤K,W≤2000
#### 输出
> 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]表示还剩0到i元,还可以被警告j次的最优期望步数。

代码

#include<map>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define M (l+(r-l)/2)
#define bug(a) cout<<#a<<" = "<<a<<endl; using namespace std; typedef __int64 LL; const int maxn = 2222; int n, m; double dp[maxn][22]; int main() {
memset(dp, 0x7f, sizeof(dp));
printf("%lf\n",dp[0][0]);
memset(dp[0], 0, sizeof(dp[0]));
for (int i = 1; i < maxn; i++) {
for (int j = 1; j < 17; j++) {
//k表示的是取走k个的情况。
//如果剩余的钱数<k,那么你就会用掉一次警告并且你能知道剩余的钱数<k。
//如果剩余的钱数>=k,那么你就不会被警告,并且剩余的钱数<i-k。
for (int k = 1; k <= i; k++) {
//这边的min体现了选择的是最优策略
dp[i][j] = min(dp[i][j], k*1.0 / (i + 1)*dp[k - 1][j - 1] + (i - k + 1)*1.0 / (i + 1)*dp[i - k][j] + 1);
}
}
}
while (scanf("%d%d", &n, &m) == 2 && n) {
//m>=15次的时候二分策略就一定能定位了。
m = min(15, m);
printf("%.6lf\n", dp[n][m]);
}
return 0;
}

HDU 5781 ATM Mechine 期望dp的更多相关文章

  1. HDU 5781 ATM Mechine (概率DP)

    ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...

  2. hdu 5781 ATM Mechine dp

    ATM Mechine 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...

  3. 【动态规划】HDU 5781 ATM Mechine

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 题目大意: 一个人有[0,K]内随机的钱,每次可以随意取,但是不知道什么时候取完,取钱超过剩余 ...

  4. HDU 5781 ATM Mechine

    题目大意:某个未知整数x等概率的分布在[0,k]中.每次你都可以从这个整数中减去一个任意整数y,如果x>=y,那么x=x-y,操作次数累计加1:否则,将会受到一次错误提示.当错误提示超过w次,将 ...

  5. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  6. HDU 3853 LOOPS:期望dp【网格型】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...

  7. HDU 6656 Kejin Player (期望DP 逆元)

    2019 杭电多校 7 1011 题目链接:HDU 6656 比赛链接:2019 Multi-University Training Contest 7 Problem Description Cub ...

  8. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  9. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. UISearchBar去除背景颜色

    UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:frame]; //这个设置背景透明可能无效 searchBar.background ...

  2. ASP.NET中@Page指令中的AutoEventWireup

    AutoEventWireup:指示控件的事件是否自动匹配 (Autowire).如果启用事件自动匹配,则为 true:否则为 false.默认值为 true.如果设为false,则事件不可用.有关更 ...

  3. SQL Server :DBLINK创建及使用

    Exec sp_droplinkedsrvlogin bvtwfld12,Null --若存在先刪除Exec sp_dropserver bvtwfld12EXEC sp_addlinkedserve ...

  4. SQL中如何检查死锁

    SQL中如何检查死锁 编写人:CC阿爸 2014-6-15 在日常SQL数据库的操作中,SQL偶尔会出现表被死锁的问题.比如: 在执行事务时,突然中止事务.系统肯定会锁表. 大批量数据操作时,由于网络 ...

  5. sprintf函数减少字符串拼接错误

    $return_string=""; foreach($cat_list as $value){ $return_string .= sprintf('<dd>< ...

  6. SBM is Not Sale And Run Company

    data = """ Well,We will bet you dollars to donuts,there are so many crusher provider ...

  7. WIN7 X64 解决无法安装IE11,以及无法点击微软升级包MSU的问题

    一般在官方下载的文件是MSU格式的后缀文件,这个文件属于系统升级包补丁:下载完毕之后直接点击安装会报错,错误提示如下:安装程序遇到错误:0x80070422 无法启动服务,原因可能是已被禁用或与其相关 ...

  8. wing IDE破解方法

    WingIDE是我接触到最好的一款Python编译器了.但其属于商业软件,注册需要一笔不小的费用.因此,这篇简短的文章主要介绍了破解WingIDE的方法.破解软件仅供学习或者教学使用,如果您是商业使用 ...

  9. JS实现浏览器的title闪烁

    经常可以看见的title里面的消息提示,下面是JS的一种实现方法:主要是通过setTimeout方法设置一个定时器,切换消息提示,从而达title到消息提示的闪烁. <html> < ...

  10. SQL语句基础之 单表查找

    Sql语句之 单表查询 一.一般查询 1.查看表中的所有记录 以及 所有字段(属性) 语句 : select * from student; 2.只查看某些字段 语句:select sname,sex ...