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. plsql中文乱码问题(显示问号)

    问题:打开plsql,执行sql语句,中文显示乱码: 解决方案: 输入sql语句select userenv('language') from dual查看数据库字符集 输入sql语句select * ...

  2. Jsp内置对象-session

    session内置对象介绍 个人理解:session因为是唯一的, session是与请求有关的会话期,它是java.servlet.http.HttpSession类的对象,用来表示和存储当前页面的 ...

  3. Local IIS 7.0 - CS0016: Could not write to output file / Microsoft.Net > Framework > v4.0.30319 > Temporary ASP.NET Files

    This week I went nuts over my local IIS. I have never swore to a machine that much in my whole life. ...

  4. 通过调整表union all的顺序优化SQL

    操作系统:Windows XP 数据库版本:SQL Server 2005 今天遇到一个SQL,过滤条件是自动生成的,因此,没法通过调整SQL的谓词达到优化的目的,只能去找SQL中的“大表”.有一个视 ...

  5. OC相关-02:oc和c的基本差异

    前言: 面向过程和面向对象. 简单的说,面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用. 面向对象是把构成问题事务分解成各个对象,建立对象的目的不 ...

  6. LINQ 101——分组、Set、转换、Element

    一.Grouping(分组) 例1:对于0-9数按被3整除的结果分组 代码: static void Linq1() { , , , , , , , , , }; var numModBy3 = fr ...

  7. 选取两个有序数组中最大的K个值,降序存入另一个数组中

    原题: 假设有两个有序的整型数组int *a1, int *a2,长度分别为m和n.试用C语言写出一个函数选取两个数组中最大的K个值(K可能大于m+n)写到int *a3中,保持a3降序,并返回a3实 ...

  8. 适合自己的vim配置文件

    主要用来写c++的:clang-completer这个是单独安装的,其他的都采用的vundle安装完成. clang-completer:只在centos7.2上安装成功过,6.4上失败了.先要安装一 ...

  9. 也谈Excel导出

    吐槽 Excel导出在天朝的软件大环境下,差点成为软件开发必备.俺就遇到过,所有报表不提供导出功能,就能不验收的囧事.报表能查看能打印能形成图表已经完美,实在搞不懂导出excel有个毛用,但是公司依靠 ...

  10. gpfdist工具的初级使用

    gpfdist工具的使用主要两步: 第一步:打开gpfdist服务: gpfdist -d /home/admin -p -l /tmp/gpfdist.log & 参数解释: -d 数据文件 ...