ZOJ3640之简单慨率DP
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的更多相关文章
- hdu4035之经典慨率DP
Maze Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submi ...
- 【bzoj3687】简单题 背包dp+STL-bitset
题目描述 小呆开始研究集合论了,他提出了关于一个数集四个问题:1.子集的异或和的算术和.2.子集的异或和的异或和.3.子集的算术和的算术和.4.子集的算术和的异或和.目前为止,小呆已经解决了前三个问题 ...
- 简单状压dp的思考 - 最大独立集问题和最大团问题 - 壹
本文参考:CPH ,USACO Guide (大佬请越过,这是初学笔记,不要吐槽内容) 前置知识:位运算基础,动态规划基础 介绍 状态是元素的子集的动态规划算法,可以用位运算来高效的优化. 那么第一道 ...
- [CF225C] Barcode (简单DAG上dp)
题目链接:http://codeforces.com/problemset/problem/225/C 题目大意:给你一个矩阵,矩阵中只有#和.两种符号.现在我们希望能够得到一个新的矩阵,新的矩阵满足 ...
- cojs 简单的数位DP 题解报告
首先这道题真的是个数位DP 我们考虑所有的限制: 首先第六个限制和第二个限制是重复的,保留第二个限制即可 第五个限制在转移中可以判断,不用放在状态里 对于第一个限制,我们可以增加一维表示余数即可 对于 ...
- [Swust OJ 648]--简单字典(数位dp)
题目链接:http://acm.swust.edu.cn/problem/0648/ Time limit(ms): 1000 Memory limit(kb): 65535 有这样一本字典,它每 ...
- 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 ...
- HDU3480-Division-斜率dp
首先想到的就是sort一下,然后每个集合都在排过序的数组里面取,不重复. 这样就推出公式dp[i][j] = min(dp[k][j-1] + (s[i]-s[k+1])^2) 其中dp[i][j]为 ...
- HDU3507-Print Article-斜率dp入门题
为了学CDQ分治,从斜率dp和凸包开始做吧.. 代码就是维护一个凸包.利用递增的性质丢掉不合适的点. http://www.cnblogs.com/Rlemon/p/3184899.html 代码学的 ...
随机推荐
- Android 4.4环境搭建——Android SDK下载与安装
学习开发Android应用程序,须要下载安装Android SDK.在Android的官方站点的二级域名http://developer.android.com/index.html中.能够下载到完整 ...
- JVM内存结构、垃圾回收那点事(转)
翻看电脑的文件夹,无意看到了9月份在公司做的一次分享,浏览了一下"婆婆特",发现自己在ppt上的写的引导性问题自己也不能确切的回答出来,哎,知识这东西,平时不常用的没些日子就生疏了 ...
- nginx随着passenger构造ruby on rails页
1.备份nginx简介 cp /opt/nginx/html/nginx.conf /opt/nginx/html/nginx.conf.bak 2.编者nginx简介 server { listen ...
- 大约cocos2d-X 3.x使用引擎版本自带的物理引擎Physics
今天打算用BOX2D物理引擎, 我想我以前听说过一些时间cocos2d-X在3.0版本封装自己的物理引擎Physics, 听名字很霸气量, 这的确是一个比BOX2D非常多( 毕竟是基于BOX2D封装的 ...
- Html5 拖放上传图片
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- 小说mvvm
与多样化和复杂的前,设计模式不再是后端专有名词.从最初的面向对象的,框架制定了到现在为止mvc等一下,今天,它主要是关于Model-View-ViewModel(MVVM). 对于mvc大家可能都会相 ...
- 一个非常有用的函数——COALESCE
原文:一个非常有用的函数--COALESCE 很多人知道ISNULL函数,但是很少人知道Coalesce函数,人们会无意中使用到Coalesce函数,并且发现它比ISNULL更加强大,其实到目前为止, ...
- nginx源代码分析--读请求主体(1)
首先,读取请求体已进入HTTP要求11相,我们需要做的请求正文部分处理一些模块,所以这个模块需要注册功能在这个阶段,在阅读功能要求的身体ngx_http_read_client_request_bod ...
- C# 字符串知识整理
新知识点,只是对于本人来说而已. 系统处理文本的方式 [新知识点].NET Framework .NET Framework的定义:其包含了一个公共语言运行时(Common Language Runt ...
- 移动端 new CustomEvent('input') 兼容问题
最近在 安卓自带浏览器 上发现 new CustomEvent('input') 不兼容 解决办法 (function () { if(!!window.CustomEvent) return; f ...