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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/286775.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/286775.shtml
英文地址,請注明出處:http://en.pswp.cn/news/286775.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android之讓手機能識別當前app為瀏覽器類型的APP

1 、問題 我們設置手機默認瀏覽器的時候&#xff0c;我們一般在“設置”頁面&#xff0c;點擊"默認應用管理“&#xff0c;然后再點擊瀏覽器&#xff0c;發現里面沒有當前的app,但是會有一些QQ瀏覽器(前提手機安裝了)或者其它瀏覽器&#xff0c;我們怎么讓系統能識別自己…

反射調用 java bean的set和get方法

v一、使用java.beans.PropertyDescriptor import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method;public class PropertyUtil {private static final String SET_PREFIX "…

八、后臺與數據庫(IVX 快速開發教程)

八、后臺與數據庫 在 iVX 中 數據庫 作為數據存儲倉庫&#xff0c;通過 數據庫 可以永久性存儲存儲數據&#xff0c;而 后臺服務 起到數據傳輸作用&#xff0c;將 數據庫 的數據傳輸到前臺頁面之中&#xff0c;頁面再使用這些數據。 文章目錄八、后臺與數據庫8.1.1 數據庫添加…

React-引領未來的用戶界面開發框架-讀書筆記(四)

第10章 動畫 動畫可以讓用戶體驗變得更加流暢自然&#xff0c;而React的TransitionGroup插件配合CSS3可以讓我們在項目中整合動畫效果的變得易如反掌。 通常情況下&#xff0c;瀏覽器中的動畫都擁有一套極其命令式的API&#xff0c;你需要選擇一個元素并主動移動它或者改變它的…

Android Studio開發環境搭建準備

Android Studio 是一個Android開發環境&#xff0c;基于IntelliJ IDEA. 類似 Eclipse ADT&#xff0c;Android Studio 提供了集成的 Android 開發工具用于開發和調試。 Android Studio開發環境搭建前&#xff0c;我們需要進行安裝前的準備工作&#xff0c;本篇以在Windows 7平臺…

管理中眼鏡蛇效應

這個世界的事物經常會很奇怪。當你做了一個出發點很好的決定后&#xff0c;結果未必是向你預期的方向發展&#xff0c;甚至適得其反。作為企業/組織/團隊的管理者&#xff0c;經常會在實際管理中&#xff0c;制定了錯誤的績效激勵辦法&#xff0c;使得整體活動走向與初始激勵目…

九、二手信息站點后臺完成 (IVX 快速開發教程)

九、二手信息站點后臺完成 了解完后臺實現后&#xff0c;我們開始為該二手商品站點完成完成后臺制作。 文章目錄九、二手信息站點后臺完成9.1.1 完成二手信息站點注冊功能9.1.2 完成二手信息站點登錄功能9.1.3 完成商品發布功能9.1.4 首頁信息獲取9.1.5 詳情頁內容9.1.1 完成二…

Android之自定義帶圓角的水紋波效果

1 需求 自定義帶圓角的水溫波效果 2 代碼實現 bg_navigation_ripple.xml <?xml version"1.0" encoding"utf-8"?> <ripple xmlns:android"http://schemas.android.com/apk/res/android"android:color"color/c3"><i…

爬蟲是什么?起什么作用?

【爬蟲】 如果把互聯網比作一張大的蜘蛛網&#xff0c;數據便是放于蜘蛛網的各個節點&#xff0c;而爬蟲就是一只小蜘蛛&#xff0c;沿著網絡抓取自己得獵物&#xff08;數據&#xff09;。這種解釋可能更容易理解&#xff0c;官網的&#xff0c;就是下面這個。 爬蟲是一種自動…

根據實例類型反射操作數據庫(簡單通用表操作類)

這個類適用簡單的表 1.有且只有id為主鍵&#xff0c; 2.并且實例類主鍵&#xff0c;也就是id應為字段&#xff0c;其他為屬性 3.實例類名跟表名一樣&#xff0c;字段屬性跟列名一樣 public class ProType{public int id;public string type{get;set;}public int array{get;set;…

React-引領未來的用戶界面開發框架-讀書筆記(五)

第11章 性能優化 Reactde Dom diff算法使我們能夠在任意時間點高效地重新繪制整個用戶界面&#xff0c;并保證最小程度的DOM改變&#xff0c;然而&#xff0c;也存在需要對組件進行細致優化的情況&#xff0c;這時就需要渲染一個新的DOM來讓應用運行得更加高效。 shouldCompone…

oneproxy檢測主從復制同步延遲

Q:為什么要實現讀寫分離延遲檢測&#xff1f; A:就好比你在ATM機存錢&#xff0c;你老婆收到短信后樂呵呵的拿網銀APP查看&#xff0c;結果錢沒過來。其實錢已經到賬了&#xff0c;只是查詢的ATM機節點錢還沒過來。所以我們dba要監控數據&#xff0c;一旦發現錢沒有復制到另一A…

.NET 分表分庫動態化處理

介紹本期主角:ShardingCore 一款ef-core下高性能、輕量級針對分表分庫讀寫分離的解決方案&#xff0c;具有零依賴、零學習成本、零業務代碼入侵我不是efcore怎么辦這邊肯定有小伙伴要問有沒有不是efcore的,我這邊很確信的和你講有并且適應所有的ADO.NET包括sqlhelperShardingCo…

addEventListener 的事件函數的傳遞【轉載】

addEventListener 參數如下&#xff1a; addEventListener(type, listener[, useCapture]); type&#xff0c;事件名稱listener&#xff0c;事件處理器useCapture&#xff0c;是否捕獲一直把 listener 記成是響應函數&#xff0c;function 類型。相信很多人也是這么理解的。多數…

Android之elevation實現陰影效果

1 需求 需要控件實現陰影效果 2 實現 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"andr…

十、小程序實戰 (IVX 快速開發教程)

十、小程序實戰 使用小程序完成一個二手信息站點與 WebApp 實現流程類型&#xff0c;只是部分內容使用了微信小程序特有的組件&#xff0c;例如微信登錄與 WebApp 略有差別&#xff0c;其它邏輯實現較為類似。我們先制作頁面&#xff0c;之后再實現功能。 由于之前已經完成了…

【VB測繪程序設計】第一章 VB測繪程序設計概述

目 錄 第一節 測繪程序設計的意義 第二節 程序設計語言的發展 第三節 測繪程序設計語言的選擇

類屬性和實例屬性沖突

類屬性和實例屬性名字沖突怎么辦 修改類屬性會導致所有實例訪問到的類屬性全部都受影響&#xff0c;但是&#xff0c;如果在實例變量上修改類屬性會發生什么問題呢&#xff1f;class Person(object):address Earthdef __init__(self, name):self.name namep1 Person(Bob) p2…