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. sharepoint2007就地升级2010系列(四)升级数据库

    上一篇我们完成了系统的升级,今天我们来看一下SQL2005X64是如何升级到SQL2008X64的. 首先,我们先停掉所有sharepoint的服务 其实网上的文档并没有写到这一步,但是我个人觉得,要 ...

  2. Design Pattern ->Factory Method

    Layering & Contract Philosophy With additional indirection Factory Method The example code is as ...

  3. selenium profile remotedriver

    使用 FirefoxProfile FirefoxProfilefp = new FirefoxProfile(); // set something on the profile... Desire ...

  4. [转载]在VB.Net中获取COM对象的特定实例(Getting a specific instance of COM object in VB.Net)

    转载:http://www.it1352.com/534235.html 问题: I am writing a Windows Form application in .Net to list all ...

  5. STM32-开发环境搭建-STM32CubeMX-安装及配置

    STM32CubeMX系列教程之1.流水灯 刚刚接触到STM32CubeMX软件,感觉挺有意思,动动鼠标使STM32开发变得简单,特写文与大家分享.但具体性能如何还需测试. 硬件开发中的流水灯相当于软 ...

  6. Javascript作业—封装type函数,返回较详细的数据类型

    Javascript作业—封装type函数,返回较详细的数据类型 思路: 1 取typeof的值,如果是数字.函数等非对象类型,直接取类型 2 如果是object类型,则调用Object.protot ...

  7. Kruskal算法求最小生成树

    Kruskal算法是根据权来筛选节点,也是采用贪心算法. /// Kruskal ///初始化每个节点为独立的点,他的祖先为自己本身 void made(int n) { ; i<=n; i++ ...

  8. Spring 远程调用工具类RestTemplateUtils

    Spring 远程调用Rest服务工具类,包含Get.Post.Put.Delete四种调用方式. 依赖jar <dependency> <groupId>org.spring ...

  9. 【转】git 删除本地分支和远程分支、本地代码回滚和远程代码库回滚

    转载自:http://m.blog.csdn.net/blog/lihongli528628/45483463 [git 删除本地分支] git branch -D br [git 删除远程分支] g ...

  10. CUDA数组分配

    原问链接 概述:数组分配可以通过cudaMallocArray()和cudaMalloc3DArray() 1.cudaMallocArray() cudaError_t cudaMallocArra ...