日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu-5781 ATM Mechine(dp+概率期望)

發布時間:2023/12/9 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu-5781 ATM Mechine(dp+概率期望) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:

ATM Mechine

Time Limit: 6000/3000 MS (Java/Others)???

?Memory Limit: 65536/65536 K (Java/Others)


Problem Description 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.

?

Input The input contains multiple test cases.
Each test case contains two numbers K and W.
1K,W2000

?

Output For each test case output the answer, rounded to 6 decimal places.

?

Sample Input 1 1 4 2 20 3

?

Sample Output 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; }

  

轉載于:https://www.cnblogs.com/zhangchengc919/p/5731986.html

總結

以上是生活随笔為你收集整理的hdu-5781 ATM Mechine(dp+概率期望)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。