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>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 2010, INF = 0x3F3F3F3F;
#define MS(a, num) memset(a, num, sizeof(a))
#define PB(A) push_back(A)
#define FOR(i, n) for(int i = 0; i < n; i++)
double dp[N][20];
void solve(int n, int m){
	for(int i = 0; i <= m; i++){
        dp[0][i] = 0;
	}
	for(int i = 1 ; i <= n; i++){
        dp[i][0] = INF;
	}
	for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            dp[i][j] = INF;
            for(int k = 1; k <= i + 1; k++){
                dp[i][j] = min(dp[i][j], (k * dp[k - 1][j - 1] + (i - k + 1) * dp[i - k][j] ) / (i + 1) + 1);
            }
        }
	}
}

int main(){
    solve(2008, 15);
    int k, w;
    while(~scanf("%d %d", &k, &w)){
        w = min(w, 15);
        printf("%.6f\n", dp[k][w]);
    }
    return 0;
}

  

时间: 2024-10-05 23:10:01

HDU5781 ATM Mechine(DP 期望)的相关文章

多校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

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>

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

2017 ICPC Asia Urumqi A.coins (概率DP + 期望)

题目链接:Coins Description Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the heads facing down onto the table and the tails upward. For exactly mm times they select any kk of the coins and toss them into the

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

Codeforces 123E Maze(树形DP+期望)

[题目链接] http://codeforces.com/problemset/problem/123/E [题目大意] 给出一棵,给出从每个点出发的概率和以每个点为终点的概率,求出每次按照dfs序从起点到达终点的期望. [题解] 首先对于期望计算有X(x,y)=X(x)*X(y),所以对于每次dfs寻路只要求出其起点到终点的期望步数,乘上起点的概率和终点的概率即可.对于一个固定起点和终点的dfs寻路,我们可以发现如果一个点在必要路径上,那么这条路被走过的期望一定为1,如果不在必要路线上,那么走

hdu 3853 LOOPS(概率 dp 期望)

Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth called LOOPS. The planform of the LOOPS

CF839 C 树形DP 期望

给一颗树,求从根出发路径长度的期望是多少. 树形DP 要想清楚期望的计算 /** @Date : 2017-08-12 23:09:41 * @FileName: C.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #de

POJ 2096 Collecting Bugs(dp 期望)

题目链接:http://poj.org/problem?id=2096 Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n ca