ZOJ3640Help Me Escape(师傅逃亡系列•一)(数学期望||概率DP)
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[],师傅也有一个初始战斗力f0。每天,师傅会随机选择一个妖怪决斗,如果打得赢ft>c[],就可以逃出去,逃出去要t[]天,毕竟超人不会飞;否则,师傅会不甘心,当天他会拿出秘籍练功,将自己变强,f(t+1)=f(t)+c[],第二天寻找下一次机会。问师傅能够逃脱可怕的妖怪,继续追求去印度吃手抓饼的梦想的天数的数学期望day。
思路:
设dp[F]是战斗力为F时,逃离的天数期望。(答案是dp[f])。则有公式。
dp[F]= Σ 1/n * t[i] ,F>c[[i]
+∑ 1/n * dp[F+c[i]] ,F<=c[i]
经验:
数学期望题目大多数需要逆推。 此处逆推的方式是记忆化。而且此题,F是单增的,而且有很明显的边界,即F达到大于最大的C[]的时候,就不会再向下面搜索了,所以记忆化搜索很有效。实在想不出顺推的DP,就记忆化逆推吧。不然DP烧脑壳。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const double P=(1.0+sqrt(5.0))/2.0;
const int maxn=;
int c[maxn],t[maxn],n,f;double dp[maxn];
double dfs(int F)
{
if(dp[F]>) return dp[F];
for(int i=;i<=n;i++){
if(F>c[i]) dp[F]+=1.0*t[i];
else dp[F]+=dfs(F+c[i])+1.0;
}
dp[F]=dp[F]/(1.0*n);return dp[F];
}
int main()
{
while(~scanf("%d%d",&n,&f)){
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
scanf("%d",&c[i]);
t[i]=(int)(1.0*c[i]*c[i]*P);
}dfs(f);
printf("%.3lf\n",dp[f]);
}return ;
}
ZOJ3640Help Me Escape(师傅逃亡系列•一)(数学期望||概率DP)的更多相关文章
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...
- POJ3682King Arthur's Birthday Celebration(数学期望||概率DP)
King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. Th ...
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
- HDU4035 Maze(师傅逃亡系列•二)(循环型 经典的数学期望)
When wake up, lxhgww find himself in a huge maze. The maze consisted by N rooms and tunnels connecti ...
- HDU3853LOOPS (师傅逃亡系列•三)(基础概率DP)
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help her friend Madoka sa ...
- 【NOIP模拟赛】书 数学+期望概率
biubiu~~~ 对于这道傻题.........我考场上退了一个多小时才推出来这个东西是排列...........然后我打的dfs效率n!logInf正好n=9是最后一个能过的数结果前三个点的n全是 ...
- 【整理】简单的数学期望和概率DP
数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...
- 【POJ】2096 Collecting Bugs(数学期望)
题目 传送门:QWQ 分析 数学期望 用$ dp[i][j] $表示发现了在$ j $个子系统里面发现了$ i $个bug到$ s $个子系统里面发现了$ n $个bug需要的期望天数. $ dp[0 ...
- ZOJ3640-Help Me Escape
Help Me Escape Time Limit: 2 Seconds Memory Limit: 32768 KB Background If thou doest well, ...
随机推荐
- java中函数传值与引用问题
从C++转java,在使用函数传对象时,碰到一点问题,今天特意验证了一下: public class App { public static void doubleTest(double d) { d ...
- C#:手把手教你用C#打包应用程序(安装程序卸载程序)
摘要:本文介绍在C#中手把手教你用C#打包应用程序(安装程序卸载程序) 1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点 ...
- Kaggle 项目之 Digit Recognizer
train.csv 和 test.csv 包含 1~9 的手写数字的灰度图片.每幅图片都是 28 个像素的高度和宽度,共 28*28=784 个像素点,每个像素值都在 0~255 之间. train. ...
- 【三小时学会Kubernetes!(四) 】Deployment实践
Deployment 部署 Kubernetes 部署可以帮助每一个应用程序的生命都保持相同的一点:那就是变化.此外,只有挂掉的应用程序才会一尘不变,否则,新的需求会源源不断地涌现,更多代码会被开发出 ...
- 深入了解JavaScript中的Symbol的使用方法
这篇文章主要介绍了深入了解JavaScript中的Symbol的使用方法,本文针对ES6版本的JS进行讲解,需要的朋友可以参考下 Symbol 是什么? Symbols 不是图标,也不是指在代码中可以 ...
- python 中str format 格式化数字补0方法
>>> "{0:03d}".format(1)'001'>>> "{0:03d}".format(10)'010'> ...
- HDU-4679-树的直径(树形dp)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- nyoj762——分解质因数+容斥+二分
第k个互质数 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的 ...
- java开发中beancopy比较
在java应用开发过程中不可避免的会使用到对象copy属性赋值. 1.常用的beancopy工具 组织(包) 工具类 基本原理 其他 apache PropertyUtils java反射 B ...
- 005——数组(五)array_diff_ukey()array_diff_uassoc()array_intersect()array_intersect_assoc()array_intersect_key()array_intersect_ukey()array_intersect_uassoc()
<?php function dump($arr) { print_r($arr); } /**array_diff_ukey() 通过回调函数的方式,返回一个数组在其他数组中不存在键名的值 * ...