2016 Multi-University Training Contest 5 ATM Mechine
ATM Mechine
本文转自:http://blog.csdn.net/queuelovestack/article/details/52096337
题意:
这题的意思还是比较费解的
Alice忘记自己在银行里存了多少钱,只记得是闭区间[0,k]内的一个整数
每次取钱,Alice会取y RMB的钱,如果余额足够则被取出,否则会被警告一次
若警告次数超过w次,Alice就会被警察抓走
在不被警察抓走的前提下,Alice采取最优策略,问期望尝试取钱多少次能够取完Alice存的所有钱
题解:
首先,我们知道ZSTU偏爱dp
那么无疑,此题为概率dp
令dp[i][j]表示Alice知道自己的存款范围是[0,i],还可以被警告j次的期望值
对于当前存款范围[0,i],Alice取y RMB的时候,会面临两种情况:
①余额不足,即 < y
此时会被警告一次
但相对的,我们可以缩小存款范围[0,y-1]
因为y RMB是取不出的,那存款最多为y-1 RMB,这点显然
所以,dp[i][j]与dp[y-1][j-1]有关
②余额足够,即 ≥ y
此时不会被警告
而且还能缩小存款范围[0,i-y]
因为原来存款最多可能有i RMB,现在取走了y RMB,那么最多还剩i-y RMB
所以,dp[i][j]还和dp[i-y][j]有关
再者,我们要先确定一下递推式,P(存款 < y) * E(存款 < y) + P(存款 ≥y) * E(存款 ≥y) + 1
由递推式来看,上述我们已经分析出了E(存款 < y)和E(存款≥y)
那我们还需要再求解一下P(存款 < y)和P(存款≥y)
因为当前存款范围是[0,i],那么,存款可能就是0i这i+1种情况,那小于y的显然就0y-1这y种情况,大于等于y的则是y~i这i-y+1种
那么可以得到状态转移方程
http://img.blog.csdn.net/20160803100016781
貌似官方题解的状态转移方程写错了
另外,Alice采取二分策略,故在最坏情况下至多被警告次
于是W:=min(W,11)就可以了。
【时间复杂度&&优化】
O(K^2*min{W,11})
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
#define PI(A) cout<<A<<endl
#define SI(N) cin>>N
#define SII(N,M) cin>>N>>M
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
#define dbg(x) cout <<#x<<" = "<<x<<endl
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS= 1e-9 ;
/* ///////////////////////// C o d i n g S p a c e ///////////////////////// */
const int MAXN= 2000 + 9 ;
double dp[MAXN][15];
int K,W;
double IN=1e200;
int main()
{
Rep(i,1,MAXN-1)
Rep(j,0,14)
{
dp[i][j]=IN;
if (!j) continue;
Rep(y,1,i)
{
dp[i][j]=min(dp[i][j],dp[i-y][j]*(i+1-y)/(i+1.0)+dp[y-1][j-1]*y/(i+1.0)+1);
}
}
while(SII(K,W))
{
if (W>11) W=11;
//这要用printf 不能用cout 会错
printf("%f\n",dp[K][W]);
}
return 0;
}
2016 Multi-University Training Contest 5 ATM Mechine的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 H
Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
- 2016 Al-Baath University Training Camp Contest-1 D
Description X is well known artist, no one knows the secrete behind the beautiful paintings of X exc ...
随机推荐
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
- linux下遍历目录(转-在于思考)
遍历目录的主要思想 由于目录就是一颗树,所以遍历目录就转换为遍历一棵树.谈到树的遍历就再熟悉不过了,有树的前序.层次和后序遍历,我使用的是前序遍历,后序遍历和前序遍历本质上一样,而层次遍历要比前两个麻 ...
- hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)
今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...
- HTML5里autofocus属性
转载:http://www.webhek.com/html5-autofocus/ HTML5给我们带来了一大堆神奇的东西.以前需要用JavaScript和Flash完成的任务,例如表单校验,INPU ...
- liunx之:wps for liunx的安装经验
首先是下载正确的安装包 WPS For Linux : 社区下载:http://community.wps.cn/download/ 社区最新包下载:http://wps-community.org/ ...
- dl,dt,dd,ul,li,ol区别
dl.dt.dd也是列表项,不过它们被忽视得比较厉害,人们只知道ul.ol.li,却经常漠视它们的存在,其实有时候,dl.dt.dd也是非常好用的,这两个家族是近亲,很多地方都是一模一样. dl类似u ...
- PHP包名解释
下载地址: http://windows.php.net/download#php-5.5 下载到的php*.zip各项文件说明: php-5.6.26-nts-Win32-VC11-x ...
- 使用Myeclipse 2015 进行 Hdp 4 windows 开发
在本地环境下进行开发,使用cygwin安装 Hdp那就是一个呵呵岂能概括. 所以啊,还是用Hdp windows进行开发测试吧.这样感觉省心点.具体 Hdp windows的安装参看前面的文章或自行G ...
- noip2011普及组——数字反转
数字反转 时间限制:1s 内存限制:128MB[问题描述]给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零 ...
- python小程序:无限求和平均
编写一个程序,重复读取数据,直到用户输入‘done’.一旦输入‘done’,打印总和.个数与平均值.如果用户输入的不是数字,使用try和except捕获异常,打印错误信息,然后跳过继续执行循环. ar ...