Help Me Escape


Time Limit: 2 Seconds      Memory Limit: 32768 KB

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

题目意思: 一个吸血鬼,每天有n条路走,每次随机选一条路走,每条路有限制,如果当这个吸血鬼的能力大于某个值c[i],那么只需要花费ti(ti = (1.0 + sqrt(5.0))/2 * c[i] * c[i]) 天的时间就可以逃出去,否则,花费1天的时间,吸血鬼的能力增加c[i],花费1天的时间,然后继续下一天的尝试。求逃出去的期望。

设dp[v] ,表示当能力值为v的时的期望。所以方程很容易写了,dp[v] = sum{ ti/n }(v直接逃出去) + sum { (1 + dp[v + c[i]])/n }(下一次逃出去) ;对于路i,如果v大于路i的限制,那么就能够用ti逃出去,概率为{1/n}否则只能进入下一天的尝试,所以需要用的时间为dp[v + c[i]] + 1 ,概率为{1/n}; 直接使用记忆化搜索的方式写。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,f,c[];
double dp[],s;
double dfs(int v)
{
int i;
if(dp[v]>)
return dp[v];
for(i=;i<=n;i++)
{
if(v>c[i])
dp[v]=dp[v]+int(s*c[i]*c[i])*1.0/n;
else
dp[v]=dp[v]+(dfs(v+c[i])+)*1.0/n;
}
return dp[v];
}
int main()
{
int i;
s=(1.0+sqrt(5.0))/2.0;
while(~scanf("%d%d",&n,&f))
{
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
scanf("%d",&c[i]);
printf("%.3lf\n",dfs(f));
}
return ;
}

dp【f】 表示攻击值为f期望出去的天数:则最大的max,2*max一定是0,dp[2*max]一定是0.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,f,c[];
double dp[],s;
int main()
{
int i;
s=(1.0+sqrt(5.0))/2.0;
while(~scanf("%d%d",&n,&f))
{
int max=;
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
scanf("%d",&c[i]);
if(max<c[i])
max=c[i];
}
max=*max;
dp[max]=;
for(i=max;i>=f;i--)
{
for(int j=;j<=n;j++)
{
if(i>c[j])
dp[i]+=int(s*c[j]*c[j])*1.0/n;
else
dp[i]+=(dp[i+c[j]]+)*1.0/n;
} }
printf("%.3lf\n",dp[f]); }
return ;
}

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

  1. ZOJ 3640 Help Me Escape:期望dp

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640 题意: 有一个吸血鬼被困住了,他要逃跑... 他面前有n条 ...

  2. zoj 3640 Help Me Escape (概率dp 递归求期望)

    题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest w ...

  3. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  4. Help Me Escape (ZOJ 3640)

    J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB ...

  5. 概率dp ZOJ 3640

    Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  6. Help Me Escape ZOJ - 3640

    Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth ...

  7. 【ZOJ】3640 Help Me Escape

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 题意:一个吸血鬼初始攻击力为f.n条路,他每次等概率选择一条路.如果攻击 ...

  8. ZOJ Problem Set - 3640 Help Me Escape

    题目大意: 有n条路,选每条路的概率相等,初始能力值为f,每条路通过的难度值为ci,当能力值大于某条路A的难度值b时,能够成功逃离,花费时间ti,小于等于时,不能逃离,天数加一天,但能力值增加b. 给 ...

  9. zoj 3640 概率dp

    题意:一只吸血鬼,有n条路给他走,每次他随机走一条路,每条路有个限制,如果当时这个吸血鬼的攻击力大于等于某个值,那么就会花费t天逃出去,否则,花费1天的时间,并且攻击力增加,问他逃出去的期望 用记忆化 ...

  10. ZOJ 3640

    很简单的概率题了 设dp[x]为能力值 为x时出去的期望 天数 #include <iostream> #include <cstdio> #include <cmath ...

随机推荐

  1. 文件图标css样式

    .list-list .ico-bookfolder { background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEU ...

  2. List和ArrayList,LinkList的区别

    接口 List<E> 是一个接口: ArrayList<E> 是一个类:是一个实现了List接口的类,因此可以List里面定义的所有的方法都实现了. 1.ArrayList是实 ...

  3. Nico Game Studio 3.地图纹理编辑 物体皮肤编辑

    完成功能: 1.地图纹理编辑功能. 图层编辑,添加/删除纹理,地图编辑.网格绘制.

  4. win7下配置apache和php

    1.软件装备 PHP:http://php.net/downloads.php non-thread-safe是非安全线程主要与IIS搭配环境. thread-safe安全线程与Apache搭配环境. ...

  5. (转)php连接mysql如何判断数据为空?

    <?php$result_a=mysql_query("select * from product_tag where product_id=$row[id]");$num ...

  6. C#当中的多线程_任务并行库(上)

    复习: 第三章内容中我们提到了三种异步编程模型,这里简单复习一下,分别如下 1.APM(异步编程模式):形如Beginxxx,Endxxx. 2.EAP(基于事件的异步编程模式):这个我们在.net中 ...

  7. SQL反模式部分内容笔记

    规范化: 1, 以一种我们能够理解的方式表达这个世界中的事物; 2, 减少数据冗余存储, 防止异常或者不一致的数据; 3, 支持完整性约束.  Tips: 提高数据的性能不在此列表中. 意义: 规范化 ...

  8. CSS 尺寸 (Dimension)

    CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度.同样,它允许你增加行间距. 更多实例 设置元素的高度 这个例子演示了如何设置不同元素的高度. 使用百分比设置图像的高度 这个例子演 ...

  9. C++专题 - Qt是什么

    Qt是一个1991年由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架.它既可以开发GUI程式,也可用于开发非GUI程式,比如控制台工具和服务器.Qt是面向对象的框架,使用特殊的代码生成扩展(称 ...

  10. 函数还能这样玩儿~实现类似add(1)(2)(3)的函数

    人生的第一份前端工作找到了,感谢大神主子们给半路出家自学的我这么多的机会,很高兴正式踏上客观又乐趣满满的程序员之路,哇咔咔咔. ​ 分享一个准备面试时遇到的一个有趣的问题: 要求实现类似add(1)( ...