2016多校训练Contest5: 1001 ATM Mechine hdu5781



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 1 4 2 20 3
 

Sample Output
  
  
1.000000 2.400000 4.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 1 4 2 20 3
 

Sample Output
   
   
1.000000 2.400000 4.523810
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值