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. 如何用js检测判断时间日期的间距

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. wcf入门教程

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

  3. arcgis engine - 添加图例,指北针.

    esri帮助提供了使用比例尺的方法: Working with map surrounds 主要代码为: public void AddMapSurround(IPageLayout pageLayo ...

  4. 【转】.Net中通过反射技术的应用----插件程序的开发入门

    转自:http://www.cnblogs.com/winloa/archive/2012/03/25/2416355.html .Net中通过反射技术的应用----插件程序的开发入门 再开始之前,先 ...

  5. 242. Valid Anagram(C++)

    242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. ...

  6. JQuery.imgAreaSelect 参数说明

    imgAreaSelect 参数说明: 参数 描述 aspectRatio 设定选取区域的显示比率,如:”4:3“ autoHide 如果设置为true,当选择区域选择结束时消失,默认值为:false ...

  7. 使用jQuery验证用户名是否存在,达到局部刷新的效果

    <%@ page pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  8. sublime text 2代码片段(Snippet)功能的使用

    “snippet”在英语里面是“片段”的意思.当我们编码时候,通常想要打几个简略的字符串,就出来一些固定的模板. 例如:使用snippet在新建文件时快速生成HTML头部信息等. 定义很简单,菜单:t ...

  9. php截取字符串,无乱码

    今天面试,有一道题,要求截取中文字符无乱码. 当时因为要赶去另一家去面试,没有仔细分析. 虽然现在供职的这家公司b2c项目正在用,因为当时赶项目,是网上拿来直接用的. 回来以后再重新整理了一下. 代码 ...

  10. AppDomain与进程、线程、Assembly之间关系

    AppDomain是CLR的运行单元,它可以加载Assembly.创建对象以及执行程序 AppDomain是CLR实现代码隔离的基本机制.   每一个AppDomain可以单独运行.停止:每个AppD ...