2016多校训练Contest5: 1001 ATM Mechine hdu5781
来源:互联网 发布:知乎下载电脑版 编辑:程序博客网 时间:2024/05/29 15:52
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.
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
Each test case contains two numbers K and W.
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 14 220 3
Sample Output
1.0000002.4000004.523810
我们用f(i,j)表示0到i的钱还可以被警告j次的期望
转移动就是f[i][j]=min(f[i][j],(i-m+1)/(i+1)*f[i-m][j]+m/(i+1)*f[m-1][j-1]+1);
这个f数组需要预处理不然会T
#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;double f[2001][21];int main(){//freopen("1001.in","r",stdin);//freopen("1001.ans","w",stdout);int i,j,m;for(i=0;i<=2000;i++)for(j=0;j<=15;j++)f[i][j]=210000000;for(j=0;j<=15;j++)f[0][j]=0;for(i=1;i<=2000;i++){for(j=1;j<=15;j++){for(m=1;m<=i;m++){double xt=double(i-m+1)/double(i+1)*f[i-m][j]+double(m)/double(i+1)*f[m-1][j-1]+double(1);f[i][j]=min(f[i][j],xt);}}}int k,w;while(scanf("%d%d",&k,&w)!=EOF){double ans=f[k][0];for(i=1;i<=min(w,15);i++)ans=min(ans,f[k][i]);printf("%lf\n",ans);}return 0;}
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.
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
Each test case contains two numbers K and W.
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 14 220 3
Sample Output
1.0000002.4000004.523810
0 0
- 2016多校训练Contest5: 1001 ATM Mechine hdu5781
- HDU5781 ATM Mechine
- HDU5781 ATM Mechine
- HDU5781 ATM Mechine
- 2017多校训练Contest5: 1001 Rikka with Candies hdu6085
- 2016多校训练Contest5: 1012 World is Exploding hdu5792
- 2016多校训练Contest5: 1007 K-wolf Number hdu5787
- 2016多校训练Contest5: 1005 Interesting hdu5785
- 2016多校训练Contest5: 1003 Divide the Sequence hdu5783
- 2016多校训练Contest5: 1004 How Many Triangles hdu5784
- 2016多校训练Contest5: 1011 Two hdu5791
- 2016多校训练Contest5: 1010 Prefix hdu5790
- hdu5781-ATM Mechine 概率DP
- hdu5781 ATM Mechine 概率dp
- HDU5781 ATM Mechine [概率dp]
- HDU5781(2016多校第五场)——ATM Mechine(动态规划)
- hdu5781 多校5 ATM Mechine【概率dp】
- HDU5781 ATM Mechine (概率dp)
- UVA10733
- 【深入Java虚拟机】之一:Java内存区域与内存溢出
- 值传递和引用传递
- arm汇编指令
- 设计模式之责任链模式
- 2016多校训练Contest5: 1001 ATM Mechine hdu5781
- matlab中在图像上划线 画圈的方法
- iOS 双击状态栏滚到视图顶部无效
- 正则表达式学习总结
- 20条Linux命令面试问答
- Redis与Memcache的对比
- js闭包二:应用场景
- Android中直播视频技术探究之---摄像头Camera视频源数据采集解析
- 回车,换行区别