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. javascript技巧字典【转藏】

    2015-12-31 js判断undefined类型 if (reValue== undefined){    alert("undefined");    }  发现判断不出来, ...

  2. iis最大连接数和队列长度

    最近公司项目的服务器出现了性能问题,关于iis负载过大,当客户问到最大连接数相关问题造成很萌的感觉,就查了相关资料: 首先让我们来看看IIS里面的这2个数字:最大并发连接数,队列长度.先说这2个数字在 ...

  3. js EasyUI前台 价格=数量*单价联动的实现

    废话,不多说,,效果图如下:

  4. OC基础-day02

    #pragma mark - Day02_01_对象的创建与使用 1)如何通过类创建一个对象 1. 类是抽象的,无法直接使用 2. 对象是类的一个具体实现,可以直接使用 3. 语法 类名 *对象名 = ...

  5. iOS:iOS开发中用户密码保存位置

    原文来自简书:http://www.jianshu.com/p/4af3b8179136/comments/1294203 如果要实现自动登录,不必每次打开应用都去登录,我们势必要把密码保存到本地.一 ...

  6. Python:列表

    #!/usr/bin/python3 #列表 是可变的,可修改的 listDemo = ["one","two","three"," ...

  7. 数据库(学习整理)----7--Oracle多表查询,三种join连接

    聚合函数:(都会忽略null数据) 常用的有5种:将字段中所有的数据聚合在一条中 .sum(字段名) :求总和 .avg(字段名) :求平均值 .max(字段名) :求最大值 .min(字段名) :求 ...

  8. ubuntu下提示/boot空间不足,解决办法

    在安装 ubuntu的时候 , 给/boot文件目录分配空间的时候,是100M,/boot可以单独分成一个区,也可以不单独分,在/(根目录)下也会自动为其创建一个boot目录.顺便提一下,linux分 ...

  9. 使用jquer获取当前时间,并赋值到input上。

    今天,做一个项目,需要将自动获取的时间能够赋值到input上.我一开始试用javascript写的,写之后使用很多办法都赋值失败,最后使用了jquery写了出来,下面附上代码. <script ...

  10. c++builder调用vc的dll

    $bcb/bin目录中有个implib.exe 把你的vc.dll和implib.exe复制到c盘根目录下 运行cmd 进入c盘根目录执行 c:\implib -a cb.lib vc.dll 会生成 ...