HDU 5781 ATM Mechine(概率dp)
生活随笔
收集整理的這篇文章主要介紹了
HDU 5781 ATM Mechine(概率dp)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://acm.split.hdu.edu.cn/showproblem.php?pid=5781
題意:
Alice要去取錢,可是她忘記有多少錢了,只知道在[0,k]的范圍之內(nèi),她每次可以選擇取y的錢,如果y超過(guò)了她的存款,那么就會(huì)警告,警告w次的話就會(huì)被抓走,問(wèn)在最多警告w次的情況下取出錢的最小期望次數(shù)。
?
思路:
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<stack> 7 #include<queue> 8 #include<cmath> 9 #include<map> 10 #include<set> 11 using namespace std; 12 typedef long long ll; 13 typedef pair<int,int> pll; 14 const int INF = 0x3f3f3f3f; 15 const int maxn = 2000 + 5; 16 17 int k,w; 18 double dp[maxn][20]; 19 20 int main() 21 { 22 //freopen("in.txt","r",stdin); 23 for(int i=1;i<=2000;i++) dp[i][0]=INF; 24 for(int i=0;i<20;i++) dp[0][i]=0; 25 for(int i=1;i<maxn;i++) 26 { 27 for(int j=1;j<20;j++) 28 { 29 dp[i][j]=INF; 30 for(int k=1;k<=i;k++) 31 dp[i][j]=min(dp[i][j],(i-k+1.0)/(i+1)*dp[i-k][j]+k/(i+1.0)*dp[k-1][j-1]+1); 32 } 33 34 } 35 while(~scanf("%d%d",&k,&w)) 36 printf("%.6f\n",dp[k][min(w,11)]); 37 return 0; 38 }?
轉(zhuǎn)載于:https://www.cnblogs.com/zyb993963526/p/7661219.html
總結(jié)
以上是生活随笔為你收集整理的HDU 5781 ATM Mechine(概率dp)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: part01.04 事件
- 下一篇: mac_android_studio_环