题目链接

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[],他初始的战斗力是f,对于第i条路,若f > c[i]他花t[i]天就能出去,否则,他就停留一天,同时战斗力增加c[i]然后再选一条路走出去,他走每条路的概率是相同的。问他逃出去的天数的期望。

注意t[i]是整数。

分析:

d[i]表示战斗力为 i 的时候的逃出去的期望。

用递归的好处是思路比较清楚,就是每次按照概率加 什么时候能逃出去的期望。

这个题也有逆推 递推的做法。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = +;
using namespace std;
double d[+], t[maxn]; //注意数组开到了2倍,因为终态可能是20000.
int c[maxn], n; double dfs(int f)
{
if(d[f]>) return d[f]; //相当于剪枝,已经计算过的不再计算 for(int i = ; i < n; i++)
{
int tmp = (int)t[i];
if(f>c[i])
d[f] += 1.0/n*(double)tmp;
else
d[f] += 1.0/n*(1.0+dfs(f+c[i]));
}
return d[f];
} int main()
{
int f, i;
while(~scanf("%d%d", &n, &f))
{
for(i = ; i < n; i++)
{
scanf("%d", &c[i]);
t[i] = (double)c[i]*c[i]*1.0*(1.0+sqrt(5.0))/2.0;
}
memset(d, , sizeof(d));
printf("%.3lf\n", dfs(f));
}
return ;
}

zoj 3640 Help Me Escape (概率dp 递归求期望)的更多相关文章

  1. zoj 3640 Help Me Escape 概率DP

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

  2. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  3. ZOJ 3329 One Person Game 【概率DP,求期望】

    题意:有三个骰子,分别有k1,k2,k3个面. 每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和. 当分数大于n时结束.求游戏的期望步数.初始分数为0 设dp[i]表示达到 ...

  4. ZOJ 3329 One Person Game(概率DP,求期望)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 题目大意: 有三个骰子,分别有K1,K2,K3个面,一次投掷可以得到三个 ...

  5. BZOJ2554 color 【概率DP】【期望DP】

    题目分析: 好题. 一开始看错题了,以为是随机选两个球,编号在前的染编号在后的. 但这样仍然能获得一些启发,不难想到可以确定一个颜色,剩下的颜色是什么就无关了. 那么答案就是每种颜色的概率乘以期望.概 ...

  6. 概率dp——逆推期望+循环迭代zoj3329

    首先要推出dp[i]的期望方程,会发现每一项都和dp[0]相关, 那我们将dp[i]设为和dp[0]有关的式子dp[i]=a[i]*dp[0]+b[i],然后再回代到原来的期望方程里 然后进行整理,可 ...

  7. ZOJ 3640 Help Me Escape:期望dp

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

  8. BZOJ 3640: JC的小苹果 [概率DP 高斯消元 矩阵求逆]

    3640: JC的小苹果 题意:求1到n点权和\(\le k\)的概率 sengxian orz的题解好详细啊 容易想到\(f[i][j]\)表示走到i点权为j的概率 按点权分层,可以DP 但是对于\ ...

  9. zoj 3329 One Person Game 概率DP

    思路:这题的递推方程有点麻烦!! dp[i]表示分数为i的期望步数,p[k]表示得分为k的概率,p0表示回到0的概率: dp[i]=Σ(p[k]*dp[i+k])+dp[0]*p0+1 设dp[i]= ...

随机推荐

  1. animate和scrollTop的使用

    // 平滑滚动到ola结果位置 var scrollHeight = $("#wrap_div")[0].scrollHeight; var curDivHeight = $(&q ...

  2. 九度OJ 1147:Jugs(罐子) (模拟、游戏)

    时间限制:1 秒 内存限制:32 兆 特殊判题:是 提交:243 解决:200 题目描述: In the movie "Die Hard 3", Bruce Willis and ...

  3. CentOS、乌班图设置固定静态IP

    CentOS.乌班图设置固定静态IP 一.centOS 1.编辑 ifcfg-eth0 文件 # vim /etc/sysconfig/network-scripts/ifcfg-eth0 2,在文件 ...

  4. 题解 P4799 【[CEOI2015 Day2]世界冰球锦标赛】

    题解 P4799 [[CEOI2015 Day2]世界冰球锦标赛] 双向搜索好题 传送门 实际上,双向搜索就是把\(a^n\)的复杂度转变成了大多为\(O(nlogna^{\frac{n}{2}})\ ...

  5. Bootstrap——组件

    1.字体图标 <span class="glyphicon glyphicon-star" aria-hidden="true"></span ...

  6. 2018年东北农业大学春季校赛 E wyh的阶乘 【数学】

    题目链接 https://www.nowcoder.com/acm/contest/93/E 思路 其实就是找阶乘的项中5的个数 末尾为什么会出现0 因为存在5的倍数和偶数相乘 有0存在 借鉴 htt ...

  7. 认识与入门 Markdown

    Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...

  8. luoguP3769 [CH弱省胡策R2]TATT

    luoguP3769 [CH弱省胡策R2]TATT PS:做这题前先切掉 P4148简单题,对于本人这样的juruo更助于理解,当然dalao就当练练手吧 题目大意: 现在有n个四维空间中的点,请求出 ...

  9. blog首页视图

    声明:此Django分类下的教程是追梦人物所有,地址http://www.jianshu.com/u/f0c09f959299,本人写在此只是为了巩固复习使用 django 是如何处理 http 请求 ...

  10. listen 55

    There are also green card qualifiers for some non-citizens who invest in America, and for refugees.难 ...