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.
 

Input
The input contains multiple test cases.
Each test case contains two numbers K and W.
1K,W2000
 

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.
 

Input
The input contains multiple test cases.
Each test case contains two numbers K and W.
1K,W2000
 

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
原创粉丝点击