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 ;
}

最新文章

  1. Celery的实践指南
  2. Zedboard安装桌面系统ubuntu及opencv(1)
  3. 【Eclipse】几个最重要的快捷键
  4. 【转】Activity启动模式 及 Intent Flags 与 栈 的关联分析
  5. Linux 命令 - echo: 显示一行文本
  6. JAVA时钟
  7. UNITY打包问题
  8. python str + int
  9. wpa_cli与wpa_supplicant的交互命令
  10. Mac浏览器全屏设置
  11. Linux系统管理员必备的监控工具(88款)
  12. 浅谈Fastfds+nginx结合_单机
  13. 【java】实现一个简单的正则:判断一个字符串是否全由数字组成
  14. Flask插件wtforms、Flask文件上传和Echarts柱状图
  15. sjms-1 面向对象
  16. 【sql注入教程】mysql注入直接getshell
  17. electron入门
  18. Mysql建了索引查询很慢
  19. Spring+Struts+Mybatis+Shiro整合配置
  20. Sklearn的使用

热门文章

  1. 数据结构——堆(Heap)大根堆、小根堆
  2. Ubuntu 安装 networkx
  3. hdu 1241 搬寝室 水dp
  4. wamp升级php7
  5. cocos2d3.0rc编译android工程
  6. Android和iOS中Cocos2dx的横屏竖屏设置
  7. 使用jenkins自动构建docker容器范例
  8. 设计模式--代理模式C++实现
  9. struts.xml中的配置常量的含义
  10. MySQL Block Nested-Loop Join(BNL)