HDU 5781 ATM Mechine
来源:互联网 发布:库里今年季后赛数据 编辑:程序博客网 时间:2024/05/22 04:33
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.
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.
1≤K,W≤2000
Each test case contains two numbers K and W.
Output
For each test case output the answer, rounded to 6 decimal places.
Sample Input
1 14 220 3
Sample Output
1.0000002.4000004.523810求期望,直接dp把答案都跑出来就好了,瞎猜了一波单调,貌似对了?
#include<set>#include<map>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef __int64 LL;const int low(int x) { return x&-x; }const double eps = 1e-8;const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 2e3 + 10;int T, n, m;double dp[N + 1][N + 1];int main(){ rep(i, 0, N) dp[0][i] = 0; rep(i, 1, N) dp[i][1] = dp[i - 1][1] * i / (i + 1) + 1; rep(i, 1, N) { int k = 1; rep(j, 2, N) { dp[i][j] = INF; int kk = 1; for (k; k <= i; k++) { if (dp[i][j] > (dp[i - k][j] * (i - k + 1) + dp[k - 1][j - 1] * k) / (i + 1)) { dp[i][j] = (dp[i - k][j] * (i - k + 1) + dp[k - 1][j - 1] * k) / (i + 1); kk = k; } if (kk < k) break; } k = kk; dp[i][j] += 1; //printf("%d %d\n", i, kk); //int k = (i + 1) / 2; //dp[i][j] = (dp[i - k][j] * (i - k + 1) + dp[k - 1][j - 1] * k) / (i + 1) + 1; } } while (scanf("%d%d", &n, &m) != EOF) { printf("%.6lf\n", dp[n][m]); } return 0;}
0 0
- HDU 5781 ATM Mechine
- hdu 5781 ATM Mechine
- HDU 5781 ATM Mechine
- 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
- HDOJ 5781 ATM Mechine
- [HDU 5781] ATM Mechine (带有最优的期望)
- HDU 5781--ATM Mechine(记忆化搜索+暴力)
- HDU 5781 ATM Mechine(概率DP求期望)
- Oracle EBS 用户密码复杂度校验
- 数据库的垂直切分和水平切分
- java 输入流异常处理并重新输入,无限循环抛异常问题处理
- Error72error LNK1181: cannot open input file 'opencv_world310.lib'E:\VC-WORK\FaceTrainVS2010_new\
- centos6.5 安装zeromq及php-zmq扩展
- HDU 5781 ATM Mechine
- 网页爬虫之cookie自动获取
- 内存管理机制
- 好玩的C语言数组!!(冒泡排序数组)
- Mysql 视图笔记
- [其他]Git常用指令
- ggplot2-ggtheme样例表
- 例题4-3 救济金发放 UVa133
- Android Studio常见问题解决方案