题目链接:

ATM Mechine

Time Limit: 6000/3000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)

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.
1≤K,W≤2000
 
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
 
题意:

问等概率为[0,k]中的一个,最多被警告w次,问取钱次数的最小期望是多少;
 
思路:
 
题解讲的很清楚了,就是dp啦,二分可知警告次数不超过15次,每次选一个数取,能取出来和不能取出来两种情况,加在一起就是题解的式子了:
dp[i][j]=min( dp[i-k][j]*(i-k+1)/(i+1)+dp[k-1][j-1]*k/(i+1)+1 )
边界就是dp[0][i]=0;其他的要正无穷;
 
AC代码:
 
/************************************************
┆ ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓   ┏━┛ ┆
┆  ┃   ┃  ┆      
┆  ┃   ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃    ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+10;
const int maxn=2e3+14;
const double eps=1e-8; double dp[maxn][17]; inline void Init()
{
For(i,1,maxn-5)For(j,0,16)dp[i][j]=inf;
For(j,1,16)dp[0][j]=0;
For(i,1,maxn-5)
{
For(j,1,16)
{
For(x,1,i)
{
dp[i][j]=min(dp[i][j],dp[i-x][j]*(i-x+1)/(i+1)+dp[x-1][j-1]*x/(i+1)+1);
}
}
} }
int main()
{
Init();
int k,w;
while(cin>>k>>w)
{
printf("%.6lf\n",dp[k][min(w,15)]);
}
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 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 ATM Mechine Time Limit: 6000/3000 MS (Java/Othe ...

  4. HDU 5781 ATM Mechine

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

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

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

  6. [LnOI2019]加特林轮盘赌(DP,概率期望)

    [LnOI2019]加特林轮盘赌(DP,概率期望) 题目链接 题解: 首先特判掉\(p=0/1\)的情况... 先考虑如果\(k=1\)怎么做到\(n^2\)的时间复杂度 设\(f[i]\)表示有\( ...

  7. HDU-5781 ATM Mechine(概率DP)

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

  8. HDU5781 ATM Mechine(DP 期望)

    应该是machine 和POJ3783 Balls类型相似. 现在上界为i元,猜错次数最多为j时,开始猜测为k元,有两种情况: 1 猜中:(i - k + 1) * dp[i - k][j] 2 猜不 ...

  9. Codeforces1097D. Makoto and a Blackboard(数论+dp+概率期望)

    题目链接:传送门 题目大意: 给出一个整数n写在黑板上,每次操作会将黑板上的数(初始值为n)等概率随机替换成它的因子. 问k次操作之后,留在黑板上的数的期望. 要求结果对109+7取模,若结果不是整数 ...

随机推荐

  1. iOS 依据文本内容为TextView动态定义高度

    解决方式: 1.定义一个textview,在storyboard中设定该textview的constraints. 2.将高度的constraint定义到头文件里:(直接拖拽) @property ( ...

  2. hint指定index的深入理解

    http://czmmiao.iteye.com/blog/1480247创建一个表,含有位图index和b-tree index SQL> create table t as select o ...

  3. nodejs初学-----helloworld

    近期紧锣密鼓的学习了下nodejs(之前在学php.算入门了吧,可是时间关系,还没写文章,兴许要搞安卓和大数据,总之比較忙哈,计划上php要排到后面了,还请广大小伙伴不要着急) 先抄一句:Node.j ...

  4. 深入浅出Attribute (一)

    正文: 什么是Attribute?Attribute是干什么使的?Attribute与Property到底有什么区别?…… 长久以来,这些问题一直困扰着并不怎么广大的C#初学者.原因大概有两个,一是A ...

  5. Maven的安装以及在IDEA中的配置

    Maven的安装 之前的一篇博客中已经写到过了Maven的安装.这里就只给出链接了. http://www.cnblogs.com/tuhooo/p/5905569.html 版本虽然不同,但是安装的 ...

  6. POJ 1787 Charlie&#39;s Change

    多重背包 可行性+路径记录 题意是说你要用很多其它的零钱去买咖啡.最后输出你分别要用的 1,5 ,10 .25 的钱的数量. 多重背包二进制分解.然后记录下 这个状态.最后逆向推就可以. #inclu ...

  7. Nginx负载均衡简易配置

    多台Web服务器水平扩展,进行负载均衡对外服务,是一种很常见的方案. 常用方法用DNS轮询,LVS. DNS轮询虽然有配置简单的有点,但无法实现健康检查,DNS修改需要较长时间失效,对于无域名的内部服 ...

  8. PowerBuilder -- Tab控件

    在tab中关闭窗口 Close(tab_1.getparent()) 调整tab中的控件的tab oder 鼠标右键tabpage_1,选择 Tab Order菜单.

  9. ubuntu 12.10 笔记

    笔记 more ec_unitouch.log |grep Thread-4 筛选日志 打开命令行终端 ctrl + alt + t     查看版本号 : sudo lsb_release -a t ...

  10. IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(三)

    IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(三) 后台服务用户与认证 新建一个空的.net core web项目Demo.Chat,端口配置为 ...