HDU 5781 ATM Mechine

概率DP。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-8;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
    char c = getchar();  while(!isdigit(c)) c = getchar();
    int x = 0;
    while(isdigit(c)) { x = x * 10 + c - ‘0‘; c = getchar(); }
    return x;
}

double dp[2010][20];

void init()
{
    for(int i=1;i<=2000;i++) for(int j=0;j<=15;j++) dp[i][j]=999999;
    for(int i=0;i<=15;i++) dp[0][i]=0;
    for(int i=1;i<=2000;i++)
        for(int j=1;j<=15;j++)
            for(int x=1;x<=i;x++)
                dp[i][j]=min(dp[i][j],1.0*(i-x+1)/(i+1)*dp[i-x][j]+1.0*x/(i+1)*dp[x-1][j-1]+1);
}

int main()
{
    int w,k;init();
    while(~scanf("%d%d",&w,&k))
    {
        printf("%.6lf\n",dp[w][min(k,15)]);
    }
    return 0;
}
时间: 2024-10-10 00:37:01

HDU 5781 ATM Mechine的相关文章

HDU 5781 ATM Mechine(概率DP求期望)

传送门 ATM Mechine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 376    Accepted Submission(s): 165 Problem Description Alice is going to take all her savings out of the ATM(Automatic Teller Mach

【动态规划】HDU 5781 ATM Mechine

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 题目大意: 一个人有[0,K]内随机的钱,每次可以随意取,但是不知道什么时候取完,取钱超过剩余额度会警告一次,最多警告不能超过W.求期望取出钱的次数. 题目思路: [动态规划] 二分居然错了...看来二分出的答案不一定最优..起码第三个样例过不去. f[i][j]表示钱在[0,i]区间内,警告次数不超过j的期望取钱次数.那么取一次钱k相当于把钱分成两块,[0,k]和[k+1,i],即[0,k

多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率

1 // 多校5 1001 HDU5781 ATM Mechine 2 // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi-University+Training+Contest+5&source=1&searchmode=source 3 // 记忆化搜索 4 // 每次二分,决策最优,所以最多查询11次 5 // dp[i][j] 当前能确定i元情况下,还能被警告j次 6 // 下次取k,实际剩余t

ATM Mechine 概率DP

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

HDU-5781 ATM Mechine(概率DP)

题目大意:某个未知整数x等概率的分布在[0,k]中.每次你都可以从这个整数中减去一个任意整数y,如果x>=y,那么x=x-y,操作次数累计加1:否则,将会受到一次错误提示.当错误提示超过w次,将会对你的人生产生影响.现在,你的任务是将x逐步变为0,求最少操作次数的期望值.题目分析:概率DP求期望.定义状态dp(k,w)表示整数分布在[0,k],错误提示次数上限为w时的最少操作次数的期望.则dp(k,w)=min(p1*dp(k-y,w)+p2*(y-1,w-1))+1,其中p1.p2分别为k>

HDU5781 ATM Mechine(DP 期望)

应该是machine 和POJ3783 Balls类型相似. 现在上界为i元,猜错次数最多为j时,开始猜测为k元,有两种情况: 1 猜中:(i - k + 1) * dp[i - k][j] 2 猜不中 k * dp[k - 1][j - 1] 两种情况的均值即为第一次猜测为k时的期望,1 <= k <= i + 1,枚举k,取最小值. 另外其实m取不到2000,由二分思想最多十几次(开始也没想到,一直不能把n^3的复杂度降下来). #include<cstdio> #includ

HDU 5071 Chat (神一般的模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 题面: Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 2195    Accepted Submission(s): 465 Problem Description As everyone knows, DRD has

HDU 5073 Galaxy(贪心)

题目链接:HDU 5073 Galaxy 题面: Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 2571    Accepted Submission(s): 642 Special Judge Problem Description Good news for us: to release the financia

HDU 5071 Chat(2014鞍山B,模拟)

http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 702    Accepted Submission(s): 163 Problem Description As everyone knows, DRD has no girlfr