hdu-5781 ATM Mechine(dp+概率期望)
2016-08-03 10:57
357 查看
题目链接:
Memory Limit: 65536/65536 K (Java/Others)
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
The input contains multiple test cases.
Each test case contains two numbers K and W.
1≤K,W≤2000
[align=left]Output[/align]
For each test case output the answer, rounded to 6 decimal places.
[align=left]Sample Input[/align]
[align=left] [/align]
1 1
4 2
20 3
[align=left]Sample Output[/align]
[align=left] [/align]
1.000000
2.400000
4.523810
题意:
问等概率为[0,k]中的一个,最多被警告w次,问取钱次数的最小期望是多少;
思路:
题解讲的很清楚了,就是dp啦,二分可知警告次数不超过15次,每次选一个数取,能取出来和不能取出来两种情况,加在一起就是题解的式子了:
dp[i][j]=min( dp[i-k][j]*(i-k+1)/(i+1)+dp[k-1][j-1]*k/(i+1)+1 )
边界就是dp[0][i]=0;其他的要正无穷;
AC代码:
ATM Mechine
Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
The input contains multiple test cases.
Each test case contains two numbers K and W.
1≤K,W≤2000
[align=left]Output[/align]
For each test case output the answer, rounded to 6 decimal places.
[align=left]Sample Input[/align]
[align=left] [/align]
1 1
4 2
20 3
[align=left]Sample Output[/align]
[align=left] [/align]
1.000000
2.400000
4.523810
题意:
问等概率为[0,k]中的一个,最多被警告w次,问取钱次数的最小期望是多少;
思路:
题解讲的很清楚了,就是dp啦,二分可知警告次数不超过15次,每次选一个数取,能取出来和不能取出来两种情况,加在一起就是题解的式子了:
dp[i][j]=min( dp[i-k][j]*(i-k+1)/(i+1)+dp[k-1][j-1]*k/(i+1)+1 )
边界就是dp[0][i]=0;其他的要正无穷;
AC代码:
/************************************************ ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ ┏━┛ ┆ ┆ ┃ ┃ ┆ ┆ ┃ ┗━━━┓ ┆ ┆ ┃ AC代马 ┣┓┆ ┆ ┃ ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar('\n'); } const LL mod=1e9+7; const double PI=acos(-1.0); const int inf=1e9; const int N=1e6+10; const int maxn=2e3+14; const double eps=1e-8; double dp[maxn][17]; inline void Init() { For(i,1,maxn-5)For(j,0,16)dp[i][j]=inf; For(j,1,16)dp[0][j]=0; For(i,1,maxn-5) { For(j,1,16) { For(x,1,i) { dp[i][j]=min(dp[i][j],dp[i-x][j]*(i-x+1)/(i+1)+dp[x-1][j-1]*x/(i+1)+1); } } } } int main() { Init(); int k,w; while(cin>>k>>w) { printf("%.6lf\n",dp[k][min(w,15)]); } return 0; }
相关文章推荐
- HDU 5781 ATM Mechine (概率dp)(求最优策略期望)
- HDU 5781 ATM Mechine (概率dp 求期望最小)
- HDU 5781 ATM Mechine(概率DP求期望)
- hdu 5781 ATM Mechine 概率(期望)dp
- HDU 5781 ATM Mechine 多校赛 概率dp
- HDU-5781 ATM Mechine(概率DP)
- HDU 5781 ATM Mechine 期望dp
- HDU_5781_ATM_Mechine(概率期望dp)
- HDU 5781 ATM Mechine (期望DP)
- HDU 5781 ATM Mechine (概率DP)
- HDU 5781 ATM Mechine(概率dp)
- HDU 5781 ATM Mechine 16多校5 概率dp
- HDU 5781 ATM Mechine(概率dp)
- HDU 5781 ATM Mechine (概率DP)
- HDU 5781 ATM Mechine(概率DP)
- 【HDU 5781】ATM Mechine(概率DP)
- HDU 4403(Aeroplane chess ,求期望,概率DP)
- 概率DP求期望入门,HDU 4405,POj 2096,HDU 3853
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
- HDU 3853 期望概率DP