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. Oracle数据库开发

    Oracle数据库开发之PL/SQL基础实战视频课程 1 PL/SQL 简介 2 入门实例(一) 3 入门实例(二) 4 PL/SQL 变量和常量 5 PL/SQL数据类型(一) 6 PL/SQL数据 ...

  2. thinkphp标签

    1.volist标签 随后一条不一样的输出<volist name="pagehead" id="vo"> <if condition=&qu ...

  3. [NHibernate]代码生成器的使用

    目录 写在前面 文档与系列文章 代码生成器的使用 总结 写在前面 前面的文章介绍了nhibernate的相关知识,都是自己手敲的代码,有时候显得特别的麻烦,比如你必须编写持久化类,映射文件等等,举得例 ...

  4. [UML]UML系列——活动图activity diagram

    系列文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend) [UML]UML系列——类图Class [UML]UML系列——类 ...

  5. 表设置了自增后往里面插入不自增的id时的处理方法

    SET IDENTITY_INSERT 表名 ON 中间写insert语句,但是这里必须把列名更上 SET IDENTITY_INSERT 表名 OFF

  6. java基础知识(四)java内存机制

    Java内存管理:深入Java内存区域 上面的文章对于java的内存管理机制讲的非常细致,在这里我们只是为了便于后面内容的理解,对java内存机制做一个简单的梳理. 程序计数器:当前线程所执行的字节码 ...

  7. oracle中 SELECT INTO 和INSERT INTO ... SELECT区别

    在Oracle中,将一张表的数据复制到另外一个对象中.通常会有这两种方法:insert into select  和 select into from. 前者可以将select 出来的N行(0到任意数 ...

  8. 提取刷机包内system.new.dat文件

    转换 使用python脚本sdat2img来完成 sdat2img.py system.transfer.list system.new.dat system.img 输出信息 Skipping co ...

  9. EF框架的三种工作方式

    EF框架step by step(1)—Database-First EF框架step by step(2)—Model-First EF框架step by step(3)—Code-First 通过 ...

  10. selenium常用的js总结

    1. 对input执行输入 直接设置value属性, 此方法主要应对输入框自动补全以及readonly属性的element,sendkeys不稳定 比如: //inputbox is a WebEle ...