6/12

2016 Multi-University Training Contest 5

期望+记忆化DP A ATM Mechine(BH)

题意:

  去ATM取钱,已知存款在[0,K]范围内,每一次输入取出钱的金额,如果大于存款,ATM会发出警报,最多W次,问能在W次内取出所有存款的取款次数的期望值。

思路:

  设dp[k][w]表示范围存款在[0,k]内,还有w次报警机会的期望值。状态转移方程:

代码:

#include <bits/stdc++.h>

const int N = 2e3 + 5;
const int INF = 0x3f3f3f3f;
const int D = 16;
double dp[N][D];
bool vis[N][D]; double DP(int k, int w) {
if (k == 0) return 0;
if (w == 0) return INF;
if (vis[k][w]) return dp[k][w];
double &ret = dp[k][w] = INF;
for (int i=1; i<=k; ++i) {
ret = std::min (ret, DP (i-1, w-1)*i/(k+1) + DP (k-i, w)*(k-i+1)/(k+1) + 1);
}
vis[k][w] = true;
return ret;
} int main() {
int k, w;
while (scanf ("%d%d", &k, &w) == 2) {
printf ("%.6f\n", DP (k, std::min (w, 15)));
}
return 0;
}

  

2016 Multi-University Training Contest 5的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 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 ...

  3. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

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

  8. 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 ...

  9. 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 ...

  10. 2016 Al-Baath University Training Camp Contest-1 C

    Description Rami went back from school and he had an easy homework about bitwise operations (and,or, ...

随机推荐

  1. JointBoost+CRF+GraphCut做手绘草图的分割

    研究生做的稍微有点水平的就这两个项目了:一个是利用SVM做手绘草图的分类,另一个是利用JointBoost+CRF做手绘草图的分割.总结得出的经验是做研究的方法就是将别人大神的代码看懂然后改成适合自己 ...

  2. 20145204&20145212实验二报告

    实验二固件设计 步骤: 1.开发环境的配置,参考实验一 1.将实验代码拷贝到共享文件夹中. 2.在虚拟机中编译代码.对于多线程相关的代码,编译时需要加-lpthread的库.下载调试在超级终端中运行可 ...

  3. Java排序算法——拓扑排序

    package graph; import java.util.LinkedList; import java.util.Queue; import thinkinjava.net.mindview. ...

  4. ecshop 支付

    支付分成两部分 1.订单信息 2.支付日志ID 3.生成支付代码 一次性支付完成 // 支付信息 include_once('includes/lib_payment.php'); $order['l ...

  5. 5Hibernate配置及使用方法----青软S2SH(笔记)

    关于hibernate的简单配置,先看结构图,我们需要 1.还要弄一下需要的 jar包. 2.配置两个文件(hibernate配置文件和映射文件),不过映射文件可以用注解替代. 3.写一个pojo类, ...

  6. MEF 根据配置注入Service

    有这样的场景 : 现在一个接口有很多种实现类,需要根据配置,来确定确定调用哪个具体的实现类.这样使得软件扩展性大大提高 在MEF可以通过ExportMetadata 来实现这样的效果. 1.现在我们建 ...

  7. ASP.NET Session 详解

    阅读本文章之前的准备 阅读本文章前,需要读者对以下知识有所了解.否则,阅读过程中会在相应的内容上遇到不同程度的问题. 懂得ASP/ASP.NET编程 了解ASP/ASP.NET的Session模型 了 ...

  8. JSP动作元素之include

    采用include指令导入的页面输入静态导入,采用<jsp:include-/>指令属于动态导入. 语法格式如下: <jsp:include page="{relative ...

  9. 学习 opencv---(1) opencv3.1.0 组件结构浅析

    本系列是根据 浅墨大神 的opencv系列而写的,,应该大部分内容会一样..如有侵权还请告知........... 开发环境:win7 + VS2013 + opencv3.1.0 至于OpenCV组 ...

  10. mysql数据表拷贝

    select * into 目标表名 from 源表名 insert into 目标表名(fld1, fld2) select fld1, 5 from 源表名 以上两句都是将 源表 的数据插入到 目 ...