题目链接:

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. UVA LIVE-4642 - Malfatti Circles

    给出三角形三个顶点,求出三个互切的圆的半径 尽管大白鼠说能够推出公式,但是这个公式仅仅怕没那么easy推--我左看右看上看下看也推不出. 应该是要做辅助线什么的,那也-- 因为非常easy就推出了关于 ...

  2. 原生domReady封装

    核心思路: 标准浏览器(含IE9+)比较简单,直接监听DOMContentLoaded事件: 低版本的IE(IE678)两套机制: 1)尝试轮询document.documentElement.doS ...

  3. SpringMVC hibernate增加多数据源 (SSHE/SYPRO增加多数据源为例)

    SpringMVC hibernate增加多数据源 (以类SSHE/SYPRO增加多数据源为例作说明) 注:适用与SpringMVC + Hibernate的项目.其它框架的仅仅能说作參考用 配置Sp ...

  4. RGB颜色空间alpha混合的方法

    http://blog.csdn.net/xhhjin/article/details/6444782http://blog.csdn.net/xhhjin/article/details/64454 ...

  5. win10 1709正式版iso镜像下载|windows10 1709秋季创意者更新官方下载地址

    win10 1709正式版iso镜像下载|windows10 1709秋季创意者更新官方下载地址 发布时间:2017-10-18 14:27发布者:系统城-xtcjh浏览数:74458 win10 1 ...

  6. MAC平台create-react-app使用问题(command not found)

    You are able to apply the following solution: $ npm config set prefix /usr/local $ sudo npm install ...

  7. CocoaPods Podfile详解与使用

    1.为什么需要CocoaPods 在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson.AFNetworking.Reachability等等.使用这些库的时候通常需要: 下载开源库的 ...

  8. Android OkHttp的Cookie自己主动化管理

    Android中在使用OkHttp这个库的时候.有时候须要持久化Cookie,那么怎么实现呢.OkHttp的内部源代码过于复杂,不进行深究.这里仅仅看当中的HttpEngineer里面的部分源代码,在 ...

  9. 访问一个绝对地址把一个整型数强制转换 (typecast)为一个指针是合法的

    在某工程中,要求设置一绝对地址为0x67a9的整型变量的值为0xaa66.编译器是一个纯粹的ANSI编译器.写代码去完成这一任务. 解析:这一问题测试你是否知道为了访问一个绝对地址把一个整型数强制转换 ...

  10. 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列

    [BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...