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 代码学的 ...
随机推荐
- net搭建热插拔式web框架(沙箱的构建)
net搭建热插拔式web框架(沙箱的构建) 上周五写了一个实现原理篇,在评论中看到有朋友也遇到了我的问题,真的是有种他乡遇知己的感觉,整个系列我一定会坚持写完,并在最后把代码开源到git中.上一篇文章 ...
- 旧Mj下拉刷新 An instance 0xca90200 of class UITableView was deallocated while key value observers were s
An instance 0xca90200 of class UITableView was deallocated while key value observers were still regi ...
- SQL Server数据库附加失败:错误5120和错误950
再次敲机房,想參考曾经的物理模型,结果在附加数据库这一环节出现了点问题,以下总结一下. 1.附加数据库失败,错误5120 对于这样的错误,我在网上搜集了一下,主要有下面几种解决的方法: 方法一:将要附 ...
- Win10使用中的一些问题
闲来无事,怒装Win10.使用上总体来说还是不错的,比Win8好一个档次吧. 不过呢在使用中遇到两个很郁闷的问题.权且几下 1.Win10激活 使用工具:激活工具 2.激活后浏览器被挟持 这让我现在非 ...
- 成不了天才,但为何也没成"人材"?(转)
长期以来,"软件业"一直被视为"智力密集"型的"朝阳"产业,大多数从业者都受过高等教育,其平均素质居于社会各行业的前列,这个产业的顶尖人物被 ...
- 无显示仍然发挥树莓派——VNCserver设定
谁说没有显示器就不能玩树莓派的图形界面了.不要忘了VNCserver哦! VNC(Virtual Network Computing)属于一种网络显示系统,也就是说它能将完整的窗体界面通过网络传输到还 ...
- iPhone&iPad DFU及恢复模式刷机、降级教程
再次提醒,刷机需慎重处理. http://blog.csdn.net/ztp800201/article/details/11980643 iphone一共同拥有三种工作模式,各自是正常模式,恢复模式 ...
- HDU 3065 病毒在继续 (AC自己主动机)
中国标题不解释 Sample Input 3 AA BB CC ooxxCC%dAAAoen....END Sample Output AA: 2 CC: 1 输出病毒出现的次数! #includ ...
- 使用python+flask让你自己api(教程源代码)
1.背景 ok,这可能是很多朋友和我一样经常使用的各种api,例facebook的.github的.甚至微信api.因此,很多人都想使自己的api.在线教程在这方面它是非常小的,今天,我做了一个平稳, ...
- NSIS:制作软件升级安装包
原文 NSIS:制作软件升级安装包 相信不是每个人写的软件都只发布一次就可以了,肯定要有修改和维护的情况发生.在这种情况下,您可能就需要一个软件的升级安装包了. 现在,我们就来一步步把这个安装包做 ...