Help Me Escape


Time Limit: 2 Seconds      Memory Limit: 32768 KB


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

题意:

dfs记忆话搜索方式:

/*题意:
一仅仅吸血鬼,有n条路给他走,每次他随机走一条路,
每条路有个限制,假设当时这个吸血鬼的攻击力大于
等于某个值,那么就会花费t天逃出去,否则,花费1天
的时间,而且攻击力添加,问他逃出去的期望
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef long long LL;
using namespace std; const int MAX=20000+10;
int n,f,c[MAX];
double dp[MAX],p;//dp[i]表示战斗力为i时出去的期望 double dfs(int f){
if(dp[f]>0)return dp[f];
for(int i=1;i<=n;++i){
if(f>c[i])dp[f]+=(int)(p*c[i]*c[i])*1.0/n;
else dp[f]+=(dfs(f+c[i])+1)*1.0/n;
}
return dp[f];
} int main(){
p=(1.0+sqrt(5))/2.0;
while(~scanf("%d%d",&n,&f)){
memset(dp,0,sizeof dp);
for(int i=1;i<=n;++i)scanf("%d",&c[i]);
printf("%.3lf\n",dfs(f));
}
return 0;
}

递推方式:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef long long LL;
using namespace std; const int MAX=20000+10;
int n,f,c[MAX];
double dp[MAX],p;//dp[i]表示战斗力为i时出去的期望 LL cal(){
LL sum=0;
for(int i=1;i<=n;++i)sum+=(int)(p*c[i]*c[i]);
return sum;
} int main(){
p=(1.0+sqrt(5))/2.0;
while(~scanf("%d%d",&n,&f)){
int maxc=0;
for(int i=1;i<=n;++i){scanf("%d",&c[i]);maxc=max(c[i],maxc);}
LL sum=cal();
for(int i=maxc+1;i<maxc+maxc+1;++i)dp[i]=sum*1.0/n;
for(int i=maxc;i>=f;--i){
dp[i]=0;
for(int j=1;j<=n;++j){
if(i>c[j]){
dp[i]+=int(p*c[j]*c[j])*1.0/n;
}else{
dp[i]+=(dp[i+c[j]]+1)/n;
}
}
}
printf("%.3lf\n",dp[f]);
}
return 0;
}

ZOJ3640之简单慨率DP的更多相关文章

  1. hdu4035之经典慨率DP

    Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submi ...

  2. 【bzoj3687】简单题 背包dp+STL-bitset

    题目描述 小呆开始研究集合论了,他提出了关于一个数集四个问题:1.子集的异或和的算术和.2.子集的异或和的异或和.3.子集的算术和的算术和.4.子集的算术和的异或和.目前为止,小呆已经解决了前三个问题 ...

  3. 简单状压dp的思考 - 最大独立集问题和最大团问题 - 壹

    本文参考:CPH ,USACO Guide (大佬请越过,这是初学笔记,不要吐槽内容) 前置知识:位运算基础,动态规划基础 介绍 状态是元素的子集的动态规划算法,可以用位运算来高效的优化. 那么第一道 ...

  4. [CF225C] Barcode (简单DAG上dp)

    题目链接:http://codeforces.com/problemset/problem/225/C 题目大意:给你一个矩阵,矩阵中只有#和.两种符号.现在我们希望能够得到一个新的矩阵,新的矩阵满足 ...

  5. cojs 简单的数位DP 题解报告

    首先这道题真的是个数位DP 我们考虑所有的限制: 首先第六个限制和第二个限制是重复的,保留第二个限制即可 第五个限制在转移中可以判断,不用放在状态里 对于第一个限制,我们可以增加一维表示余数即可 对于 ...

  6. [Swust OJ 648]--简单字典(数位dp)

    题目链接:http://acm.swust.edu.cn/problem/0648/ Time limit(ms): 1000 Memory limit(kb): 65535   有这样一本字典,它每 ...

  7. CF 319C(Kalila and Dimna in the Logging Industry-斜率DP,注意叉积LL溢出)

    C. Kalila and Dimna in the Logging Industry time limit per test 2 seconds memory limit per test 256 ...

  8. HDU3480-Division-斜率dp

    首先想到的就是sort一下,然后每个集合都在排过序的数组里面取,不重复. 这样就推出公式dp[i][j] = min(dp[k][j-1] + (s[i]-s[k+1])^2) 其中dp[i][j]为 ...

  9. HDU3507-Print Article-斜率dp入门题

    为了学CDQ分治,从斜率dp和凸包开始做吧.. 代码就是维护一个凸包.利用递增的性质丢掉不合适的点. http://www.cnblogs.com/Rlemon/p/3184899.html 代码学的 ...

随机推荐

  1. 采用UltraISO制作U菜Win7安装盘,显现&quot;File not find /BOOT/CDMENU.EZB.ezb&quot;错误

    一机公司Win7动力password不知道.这台机器也很慢, 刷新Win7,运用32位Ghost设备ISO档.从机U之后启动盘,演出 "File not find /BOOT/CDMENU. ...

  2. UVA - 11637 Garbage Remembering Exam (组合+可能性)

    Little Tim is now a graduate,and is thinking about higher studies. However, he first needs to appear ...

  3. ListView分页显示

    出在:http://blog.csdn.net/tu_bingbing/article/details/13275107         当ListView要显示的数据过多时,为了更快的响应用户,这个 ...

  4. 基本shell编程【3】- 常用的工具awk\sed\sort\uniq\od(转)

    awk awk是个很好用的东西,大量使用在linux系统分析的结果展示处理上.并且可以使用管道, input | awk ''  | output 1.首先要知道形式 awk 'command' fi ...

  5. div+js 弹出层

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  6. SQL Server 日期相关

    原文:SQL Server 日期相关 原帖出处:http://blog.csdn.net/dba_huangzj/article/details/7657979 对于开发人员来说,日期处理或许简单,或 ...

  7. 几个cd快速提示

    cd是project师每天都会用到的命令. 今天就来分享几条和cd有关的小技巧 cd 假设你用cd ~来进入当前用户的home文件夹的话,那么能够试试直接敲cd. 相同效果,少敲两下键盘. cd - ...

  8. Scut游戏server引擎Unity3d访问

    Scut提供Unity3d Sdk包.便利的高速发展和Scut游戏server对接: 看Unity3d示为以下的比率: 启动Unity3d项目 打开Scutc.svn\SDK\Unity3d\Asse ...

  9. 使用log4j日志-配置载入问题

    1.在eclipse中,把log4j.properties放在类路径下,在项目启动时就会自己主动载入. 2.在idea中.把log4j.properties放在类路径下,可是项目启动时不能直接载入(原 ...

  10. STL源代码分析——STL算法merge合并算法

    前言 因为在前文的<STL算法剖析>中.源代码剖析许多.不方便学习.也不方便以后复习,这里把这些算法进行归类.对他们单独的源代码剖析进行解说.本文介绍的STL算法中的merge合并算法. ...