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)=Ft+c[],第二天寻找下一次机会。问师傅逃脱所用天数的数学期望。

思路:

设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"bits/stdc++.h"

 #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff;
//int t;
db dp[N];
int c[N];
int t[N];
int n,f;
db dfs(int u)
{
if(dp[u]>) return dp[u];
for(int i=;i<n;i++){
if(u>c[i]) dp[u]+=1.0*t[i]/n;
else dp[u]+=(dfs(u+c[i])+)/n;
}
if(u==f) printf("%.3f\n",dp[f]);
return dp[u];
}
int main()
{ while(scanf("%d%d",&n,&f)==){
for(int i=;i<n;i++) ci(c[i]),t[i]=int((+sqrt(5.0))/*c[i]*c[i]);
memset(dp,, sizeof(dp));
dfs(f);
}
return ;
}

ZOJ3640 概率DP的更多相关文章

  1. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  2. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  3. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  4. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  5. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

  6. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  7. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  8. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

  9. HDU 4050 wolf5x(动态规划-概率DP)

    wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. MySQL(四)

    一.使用正则表达式查询 SELECT * FROM employee WHERE name REGEXP '^ale'; SELECT * FROM employee WHERE name REGEX ...

  2. php-5.2.14 编译参数,成功的

    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/bin --with-mysql=/usr/local/mysql - ...

  3. Ubuntu 14.04 软件源服务器集合

    http://wiki.ubuntu.com.cn/Template:14.04source 服务器列表 可将 http://cn.archive.ubuntu.com/ubuntu/ 替换为下列任意 ...

  4. Azure杯年会Cosplay大赛,速来围观!

    又是一年年会时,正值各家公司红人纷纷登场之际,Azure 自然也不会缺席.我们今年的主题是:Azure 杯年会 Cosplay,秀出你最爱的角色! 在过去的一年中,Azure 智能云取得了长足的发展, ...

  5. HTML:::before和::after伪元素的用法

    随笔 - 366  文章 - 0  评论 - 392 ::before和::after伪元素的用法   一.介绍 css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:li ...

  6. 百万级数据库SQL优化大总结

    网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充. 这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉 ...

  7. HTML-JS-CSS基础

    HTML-JS-CSS基础 1.html hyper text markup language,超文本标记语言,所见即所得.web开发中用于展示功能的部分,浏览器可对其进行渲染.产生各种可视化组件,比 ...

  8. 安装纯净 ubuntu linux (非虚拟机)

    //--------------- Chinese version --------------------------------------------------// 前提条件:有另一台电脑(w ...

  9. NWERC 2013 - J (codeforces gym - 100405J)

    题目描述:给你一颗二叉树,保证每个点要么是叶子节点,要么有左右两个儿子.某些叶子节点上放着灯,请你移动最少的灯,使得整棵树平衡 对平衡的定义:对于树上的每个点左右儿子中灯数的差的绝对值≤1,那么这棵树 ...

  10. 运行npm update等命令出错后如何分析问题根源

    我今天工作时,在当前前端项目工作目录下执行命令npm update 结果遇到如下错误:registry error parsing json npm ERR! Unexpected token < ...