J - Help Me Escape

Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

Background

    If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.
    And Cain talked with Abel his brother: and it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him.
    And the LORD said unto Cain, Where is Abel thy brother? And he said, I know not: Am I my brother's keeper?
    And he said, What hast thou done? the voice of thy brother's blood crieth unto me from the ground.
    And now art thou cursed from the earth, which hath opened her mouth to receive thy brother's blood from thy hand;
    When thou tillest the ground, it shall not henceforth yield unto thee her strength; a fugitive and a vagabond shalt thou be in the earth.

—— Bible Chapter 4

Now Cain is unexpectedly trapped in a cave with N paths. Due to LORD's punishment, all the paths are zigzag and dangerous. The difficulty of the ith path is ci.

Then we define f as the fighting capacity of Cain. Every day, Cain will be sent to one of the N paths randomly.

Suppose Cain is in front of the ith path. He can successfully take ti days to escape from the cave as long as his fighting capacity f is larger than ci. Otherwise, he has to keep trying day after day. However, if Cain failed to escape, his fighting capacity would increase ci as the result of actual combat. (A kindly reminder: Cain will never died.)

As for ti, we can easily draw a conclusion that ti is closely related to ci. Let's use the following function to describe their relationship:

After D days, Cain finally escapes from the cave. Please output the expectation of D.

Input

The input consists of several cases. In each case, two positive integers N and f (n ≤ 100, f ≤ 10000) are given in the first line. The second line includes N positive integers ci (ci ≤ 10000, 1 ≤ i ≤ N)

Output

For each case, you should output the expectation(3 digits after the decimal point).

Sample Input

3 1
1 2 3

Sample Output

6.889

概率dp
求期望,记忆化搜索
#include <cstdio>
#include <cmath>
#include <cstring>
#define N 105
#define M 2500000
double f, c[N], t[N], p[M];
int n;
double dp(int ff)
{
if(p[ff] > 0.0) return p[ff];
for(int i = ; i < n; i++)
if(ff > c[i]) p[ff] += t[i] / (double)n;
else p[ff] += (1.0 + dp(ff + c[i])) / (double)n;
return p[ff];
} int main()
{
while(~scanf("%d%lf", &n, &f))
{
memset(p, , sizeof(p));
for(int i = ; i < n; i++) {
scanf("%lf", &c[i]);
t[i] = floor((1.0 + sqrt(5.0)) * c[i] * c[i] / 2.0);
}
printf("%.3lf\n", dp(f));
}
return ; }

Help Me Escape (ZOJ 3640)的更多相关文章

  1. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  2. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  3. 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...

  4. HDU 3533 Escape(BFS+预处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 题目大意:给你一张n* m的地图,人在起点在(0,0)要到达终点(n,m)有k(k<=10 ...

  5. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information ...

  6. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  7. POJ 2590 Steps (ZOJ 1871)

    http://poj.org/problem?id=2590 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1871 题目大 ...

  8. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  9. Escape (BFS + 模拟)

    Problem Description The students of the HEU are maneuvering for their military training. The red arm ...

随机推荐

  1. jdk安装环境变量设置

    设置JAVA_HOME,点击新建,变量名:JAVA_HOME,变量值:D:\java\jdk1.7.0,即刚才jdk安装的路径.   设置CLASSPATH属性,变量名:CLASSPATH,变量值:. ...

  2. 访问者模式,visitor

    定义: 表示作用于某对象结构中的各个元素的操作. 可以在不改变各元素的类的前提下定义作用于这些元素的新操作. 前提: 适用于数据结构(Element)相对稳定的系统,这样visitor中的方法就是稳定 ...

  3. SQL Server 临时表 Vs 表变量

    开始 说临时表和表变量,这是一个古老的话题,我们在网上也找到很多的资料阐述两者的特征,优点与缺点.这里我们在SQL Server 2005\SQL Server 2008版本上通过举例子,说明临时表和 ...

  4. 使用spring过程中遇到的问题

    1.java.lang.SecurityException: sealing violation: package javax.servlet is sealed java.lang.Security ...

  5. 一个js(javascript)使用案例

    <script type="text/javascript"> var Row; $(function () { // $("#Sel").clic ...

  6. Ext.net 异常统一管理,铥掉可恶的 Request Failure

    Ext.net 异常统一管理,铥掉可恶的 Request Failure 看着这样的框框是不是很不爽 灭他.也不难.. .如果全部页面都有继承一个自定义的父类 ..那整个项目代码量就只有几行了.. 单 ...

  7. [转载] Linux下高并发socket最大连接数所受的各种限制

    原文: http://mp.weixin.qq.com/s?__biz=MzAwNjMxNjQzNA==&mid=207772333&idx=1&sn=cfc8aadb422f ...

  8. CSS规范之BFC & IFC

    元素是文档结构的基础,在CSS中,每个元素生成了一个包含了元素内容的框(box,也译为"盒子").但是不同的元素显示的方式会有所不同,例如<div>和<span& ...

  9. 在PC端或移动端应用中接入商业QQ的方法

    今天看博友的博客学习了一种很有用的方法: 在页面中需要接入企业的QQ,访问网址:http://shang.qq.com/widget/consult.php.(就是API接口),然后你只需要登录你的Q ...

  10. JavaWeb 5 Tomcat

    5 Tomcat 1 Web开发入门            1.1 引入                之前的程序: java桌面程序,控制台控制,socket gui界面.javase规范      ...