hdu5781ATM Mechine

探讨了在未知确切存款金额的情况下,如何使用最佳策略从ATM中取出所有存款,并避免因过多错误尝试而被误认为窃贼的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ATM Mechine

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1357    Accepted Submission(s): 678


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
 

Author
ZSTU
 

Source
 

Recommend

wange2014   |   We have carefully selected several similar problems for you:  6022 6021 6020 6019 6018 




题意:

Alice想把自己的存款全部取出,她忘记了存款数,只记得自己的存款在[0,k]范围内的整数,奇怪的是这台机器没有查询功能,当你从ATM取出不超过你存款的数时,它会出钞,否则警告,当警告次数超过了W次的时,警察会把你带走,问Alice取出所有存款且处于安全状态的期望值

(1<=k,W<=2000)



由于k最大为2000,不计警告次数的话,采用二分策略,二分11次就够了,如果W大于11,对答案不会有太大的影响

当存款为0时,不管警告次数,答案都是0


AC代码:


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int MAXN=2000+5;
double dp[MAXN][16];//dp[i][k]代表已知存款在[0,i]范围内,还有k次警告次数时的期望值
int main()
{
        for(int i=0;i<MAXN;++i)
        {
                for(int j=0;j<16;++j)
                dp[i][j]=1e12;//初始化为INF
        }
        for(int i=0;i<16;++i)//ATM里没钱
                dp[0][i]=0;
        for(int i=1;i<=2000;++i)//k最多不超2000
        {
                for(int j=1;j<=i;++j)//每次取j元,可以取最多次数
                {
                        for(int k=1;k<=15;++k)//警告次数可以二分法2^11>1000
                        {
                                dp[i][k]=min(dp[i][k],(j*dp[j-1][k-1]+(i-j+1)*dp[i-j][k])/(i+1)+1);
                                //如果实际存款数低于这个j的话,问题就退化成了求dp[j-1][k-1]的值
                                //如果实际存款数高于或等于这个j的话,问题就退化成了求dp[i-j][k]的值
                                //(此时把范围确定到了[j,i],等价于把范围确定到了[0,i-j])
                        }
                }
        }
        int k,w;
        while(~scanf("%d%d",&k,&w))
        {
                printf("%.6f\n",dp[k][min(w,11)]);
        }
        return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值