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>=y、k<y的概率,p1=(k-y+1)/(k+1)、p2=y/(k+1)。因为你非常聪明,所以你每次都会二分的选择要减掉的整数y。根据题目的数据规模,你最多会操作log2(k)+1次,所以你被错误提示的次数最多log2(k)次。这样,便大大减少了状态数目,使得上述方程能够得以实现。

参考代码:

# include<bits/stdc++.h>
using namespace std;

const int N=2000;
const double inf=1e9;

double dp[N+5][13];

void init()
{
	for(int i=0;i<=12;++i)
		dp[0][i]=0;
	for(int i=1;i<=N;++i)
		for(int j=0;j<=12;++j) dp[i][j]=inf;
	for(int i=1;i<=N;++i) for(int j=1;j<=12;++j)
		for(int k=1;k<=i;++k)
			dp[i][j]=min(dp[i][j],1.0*(i-k+1)/(i+1)*dp[i-k][j]+1.0*k/(i+1)*dp[k-1][j-1]+1.0);
}

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

  

  

  

时间: 2024-08-29 02:16:08

HDU-5781 ATM Mechine(概率DP)的相关文章

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

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. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #in

【动态规划】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

HDU 4652 Dice (概率DP)

Dice Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0

HDU 3366 Passage (概率DP)

Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. There are only n passages to go out. For any passage i (1<=i<=n), Pi (0<=Pi<=1) denotes the probability that Bill will escape from this castle saf

[ACM] HDU 4576 Robot (概率DP,滚动数组)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

[ACM] hdu 4405 Aeroplane chess (概率DP)

Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the number

HDU 4050 wolf5x (概率DP 求期望)

题意:有N个格子,1~N,起点在0,每个格子有一个状态(0,1,2,3),每次可以跨[a,b]步, 问走完N个格子需要步数的期望,每次尽量走小的步数,即尽量走a步,不能则走a+1,-- 状态0意味着你不能踏进对应的网格. 状态1意味着你可以??步入网格用你的左腿. 状态2意味着你可以??步入网格用你的右腿. 状态3意味着你可以进入网格用任何你的腿,而接下来的步骤中,您可以使用任何的腿;即你不需要遵循上述规则. 思路:借鉴了各路大神的思想理解了下. dp[i][j] :表示走到第 i 个格子在 j

[ACM] hdu 3853 LOOPS (概率DP,递推)

LOOPS 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