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 代码学的 ...
随机推荐
- GotoTest
循环标签跳出循环 public class GotoTest { public static void main(String[] args) { int[][] array={ {1,20,3}, ...
- 【PHP】PHP获得第一章
一,PHP上部和下部壳体敏感 1)所有的用户定义的函数.类和keyword敏感. 例如以下结果输出一致: echo "hello world" Echo "hello ...
- mac提升yosemite后php 扩展修复
mac升级之后 php 正积极提升自己,导致php环境破坏 所以 例如有以下几点需要修复 1. sudo ln -s /Applications/Xcode.app/Contents/Develope ...
- 第三篇——第二部分——第三文 配置SQL Server镜像——域环境
原文:第三篇--第二部分--第三文 配置SQL Server镜像--域环境 原文出处:http://blog.csdn.net/dba_huangzj/article/details/28904503 ...
- C#枚举数和迭代器
大道至简,始终认为简洁是一门优秀的编程语言的一个必要条件.相对来说,C#是比较简洁的,也越来越简洁.在C#中,一个关键字或者语法糖在编译器层面为我们做了很多乏味的工作,可能实现的是一个设计模式,甚至是 ...
- thinkphp3.2 代码生成并点击验证码
本人小菜鸟一仅仅.为了自我学习和交流PHP(jquery,linux,lamp,shell,javascript,server)等一系列的知识.小菜鸟创建了一个群.希望光临本博客的人能够进来交流.寻求 ...
- 表复制语句select into from 与 insert into select 区别鉴赏
select into from 与 insert into select 区别鉴赏 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,fi ...
- navicat如何导入sql文件
工具--数据的传输--文件 版权声明:本文博客原创文章,博客,未经同意,不得转载.
- quick-cocos2d-x游戏开发【5】——创建菜单
一个菜单是游戏中的一个基本要素,quick在里面menuItem有两个包.一个是图片菜单.一个文本菜单. 一个.图片菜单ui.newImageMenuItem(params) 參数: image: 正 ...
- BZOJ 1212 HNOI2004 L语言 AC自己主动机(Trie树)+动态规划
标题效果:给定词的列表,并m串 每个字符串q个最长前缀,这个前缀可满足拆分成一些字符串 这些字符串中存在的词汇太 再也不怕错误的数据范围--有一个很明显Trie树能解决的问题竟然被我写的AC自己主动机 ...