Help Me Escape

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld
& %llu

Appoint description: 
System Crawler  (2014-10-22)

Description

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 cias 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

/*************************************************************************
> File Name: t.cpp
> Author: acvcla
> Mail: acvcla@gmail.com
> Created Time: 2014年10月21日 星期二 21时33分55秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 20000 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
int n,c[105],f;
double dp[maxn];
double d(int f){
if(dp[f]>0)return dp[f];
dp[f]=0;
for(int i=1;i<=n;i++){
if(f>c[i]){
int t=(1+sqrt(5))*c[i]*c[i]/2;
dp[f]+=(double)t/n;
}else{
dp[f]+=(1+d(f+c[i]))/n;
}
}
return dp[f];
}
int main(int argc, char const *argv[])
{
while(~scanf("%d%d",&n,&f)){
memset(dp,0,sizeof dp);
for(int i=1;i<=n;i++)scanf("%d",c+i);
printf("%.3f\n",d(f));
}
return 0;
}

概率dp ZOJ 3640的更多相关文章

  1. [概率dp] ZOJ 3822 Domination

    题意: 给N×M的棋盘.每天随机找一个没放过棋子的格子放一个棋子 问使得每一个每列都有棋子的天数期望 思路: dp[i][j][k] 代表放了i个棋子占了j行k列 到达目标状态的期望 然后从 dp[n ...

  2. zoj 3640 Help Me Escape 概率DP

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

  3. zoj 3822(概率dp)

    ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Ju ...

  4. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  5. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  6. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  7. zoj 3822 Domination 概率dp 2014牡丹江站D题

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  8. ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...

  9. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

随机推荐

  1. ajax(ajax开发)

    AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...

  2. post请求和get请求的区别

    1:如果表单是以post方式发送,那么表单中的数据会放在请求报文体中,发送到服务端.但是如果是以get方式提交表单,那么表单中用户输入的数据都是以URL地址的方式发送到服务端. 2:在服务端接收数据时 ...

  3. 使用hibernate优化

    a. 在查询字符串中,应该总是使用jdbc的占位符?,或使用使用命名参数:,不要自查询中使用字符串值来代替非常量值.   b.  Flush会影响性能,频繁刷新影响性能,尽量减少不必要的刷新.   c ...

  4. gitosis随记

    0.创建git用户 useradd -m git passwd git 1.安装脚本工具(gitosis依赖python) apt-get install python-setuptools 2.gi ...

  5. 【Nutch2.3基础教程】集成Nutch/Hadoop/Hbase/Solr构建搜索引擎:安装及运行【集群环境】

    1.下载相关软件,并解压 版本号如下: (1)apache-nutch-2.3 (2) hadoop-1.2.1 (3)hbase-0.92.1 (4)solr-4.9.0 并解压至/opt/jedi ...

  6. AngularJS实现表单手动验证和表单自动验证

    AngularJS的表单验证大致有两种,一种是手动验证,一种是自动验证.一.手动验证 所谓手动验证是通过AngularJS表单的属性来验证.而成为AngularJS表单必须满足两个条件: 1.给for ...

  7. [POJ] 2456 Aggressive cows (二分查找)

    题目地址:http://poj.org/problem?id=2456 最大化最小值问题.二分牛之间的间距,然后验证. #include<cstdio> #include<iostr ...

  8. yii开启gii功能

    如果不想面对黑白界面,那么yii框架,给我们提供了一个模块gii 在配置文件中main.php 再通过访问模块的方式访问gii

  9. CS找工作好文章

    我的美国CS面试经验分享 -- 转载 怎样花两年时间去面试一个人 上面列出了一些比较好的书单 cs土硕找工作总结(二) 笔试面试准备http://blog.renren.com/blog/221227 ...

  10. win8、win8.1官方版本、及安装密钥

    云盘地址:Windows 8 简体中文专业版+核心版 MSDN 正式版(32位)http://pan.baidu.com/s/1eQgiAiQSHA1:0C4A168E37E38EFB59E88443 ...