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

给出 n 条路,然后每条路有一个c[i]的困难值 和 t[i] 的逃脱天数,一个人的战斗力是 f ,当战斗力大于 c[i] 时, 花t[i]天逃出去,否则下一天随机到另一个地方, 问你这个人期望的走出去的天数是几天。
一开始考虑 dp[i][j] 表示从第 i 个位置出发,战斗力为 j 时的期望逃脱天数。这样可以得到:
1. j > c[i], dp[i][j] = t[i]
2. j <= c[i], dp[i][j] = Σ(dp[k][j+c[i]] + 1) / n
然后去枚举开始的位置,并加上记忆化搜索,感觉是可以的,但是这样做会 T 。
 /*
.
';;;;;.
'!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####|.
|##$|!;;;;;;::'':;;;;;;;;;;;;;!%$$$@#@;
;@&|;;;;;;;::'''''':;;;;;;;|$&@###@|`
.%##@|;;;;:::''''''''''::;!%&##$'
`$##@$$@@&|!!;;;:'''''::::;;;;;|&#%.
;&@##&$%!;;;;;;::''''''''::;!|%$@#@&@@:
.%@&$$|;;;;;;;;;;:'''':''''::;;;%@#@@#%.
:@##@###@$$$$$|;;:'''':;;!!;;;;;;!$#@@#$;`
`%@$$|;;;;;;;;:'''''''::;;;;|%$$|!!&###&'
|##&%!;;;;;::''''''''''''::;;;;;;;!$@&:`!'
:;!@$|;;;;;;;::''''''''''':;;;;;;;;!%&@$: !@#$'
|##@@&%;;;;;::''''''''':;;;;;;;!%&@#@$%: '%%!%&;
|&%!;;;;;;;%$!:''''''':|%!;;;;;;;;|&@%||` '%$|!%&;
|@%!;;!!;;;||;:'''''':;%$!;;;;!%%%&#&%$&: .|%;:!&%`
!@&%;;;;;;;||;;;:''::;;%$!;;;;;;;|&@%;!$; `%&%!!$&:
'$$|;!!!!;;||;;;;;;;;;;%%;;;;;;;|@@|!$##; !$!;:!$&:
|#&|;;;;;;!||;;;;;;;;!%|;;;;!$##$;;;;|%' `%$|%%;|&$'
|&%!;;;;;;|%;;;;;;;;$$;;;;;;|&&|!|%&&; .:%&$!;;;:!$@!
`%#&%!!;;;;||;;;;;!$&|;;;!%%%@&!;;;!!;;;|%!;;%@$!%@!
!&!;;;;;;;;;||;;%&!;;;;;;;;;%@&!;;!&$;;;|&%;;;%@%`
'%|;;;;;;;;!!|$|%&%;;;;;;;;;;|&#&|!!||!!|%$@@|'
.!%%&%'`|$; :|$#%|@#&;%#%.
*/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e2 + ;
const int maxm = 2e4 + ;
const int mod = 1e9 + ;
const ll INF = 1e18 + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
using namespace std; int n, m;
int cas, tol, T; int c[maxn];
int t[maxn];
double dp[maxn][maxm]; void init() {
mes(c, );
mes(t, );
mes(dp, );
} void dfs(int id, int f) {
if(dp[id][f]) return ;
if(f > c[id]) {
dp[id][f] = 1.0 * t[id];
return ;
}
double ans = 0.0;
for(int i=; i<=n; i++) {
dfs(i, f+c[id]);
ans += dp[i][f+c[id]] + 1.0;
}
dp[id][f] = ans / n;
} int main() {
while(~scanf("%d%d", &n, &m)) {
init();
for(int i=; i<=n; i++) {
scanf("%d", &c[i]);
t[i] = (int)((1.0 + sqrt(5.0)) / * c[i] * c[i]);
}
double ans = 0.0;
for(int i=; i<=n; i++) {
dfs(i, m);
ans += dp[i][m];
}
printf("%.3f\n", ans / n);
}
return ;
}

TLE

观察方程发现 dp[i][j] 的 i 每次都要去重复枚举,花费了太多的时间,那么想办法优化掉一维。
dp[i] 表示战斗力为 i 时的期望天数。
然后再去搜索每条路
1. i > c[j], dp[i] += t[j]
2. i <= c[j], dp[i] += dp[i + c[j]] + 1
然后在记忆化搜索,就能过了....
 /*
.
';;;;;.
'!;;;;;;!;`
'!;|&#@|;;;;!:
`;;!&####@|;;;;!:
.;;;!&@$$%|!;;;;;;!'.`:::::'.
'!;;;;;;;;!$@###&|;;|%!;!$|;;;;|&&;.
:!;;;;!$@&%|;;;;;;;;;|!::!!:::;!$%;!$%` '!%&#########@$!:.
;!;;!!;;;;;|$$&@##$;;;::'''''::;;;;|&|%@$|;;;;;;;;;;;;;;;;!$;
;|;;;;;;;;;;;;;;;;;;!%@#####&!:::;!;;;;;;;;;;!&####@%!;;;;$%`
`!!;;;;;;;;;;!|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;;;;::''''''''''''::;;;;;;;!$@&:`!'
:;!@$|;;;;;;;::''''''''''':;;;;;;;;!%&@$: !@#$'
|##@@&%;;;;;::''''''''':;;;;;;;!%&@#@$%: '%%!%&;
|&%!;;;;;;;%$!:''''''':|%!;;;;;;;;|&@%||` '%$|!%&;
|@%!;;!!;;;||;:'''''':;%$!;;;;!%%%&#&%$&: .|%;:!&%`
!@&%;;;;;;;||;;;:''::;;%$!;;;;;;;|&@%;!$; `%&%!!$&:
'$$|;!!!!;;||;;;;;;;;;;%%;;;;;;;|@@|!$##; !$!;:!$&:
|#&|;;;;;;!||;;;;;;;;!%|;;;;!$##$;;;;|%' `%$|%%;|&$'
|&%!;;;;;;|%;;;;;;;;$$;;;;;;|&&|!|%&&; .:%&$!;;;:!$@!
`%#&%!!;;;;||;;;;;!$&|;;;!%%%@&!;;;!!;;;|%!;;%@$!%@!
!&!;;;;;;;;;||;;%&!;;;;;;;;;%@&!;;!&$;;;|&%;;;%@%`
'%|;;;;;;;;!!|$|%&%;;;;;;;;;;|&#&|!!||!!|%$@@|'
.!%%&%'`|$; :|$#%|@#&;%#%.
*/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e2 + ;
const int maxm = 1e5 + ;
const int mod = 1e9 + ;
const ll INF = 1e18 + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
using namespace std; int n, m;
int cas, tol, T; int c[maxn];
int t[maxn];
double dp[maxm]; void init() {
mes(c, );
mes(t, );
mes(dp, );
} void dfs(int f) {
if(dp[f])
return ;
double ans1 = 0.0;
double ans2 = 0.0;
for(int i=; i<=n; i++) {
if(f > c[i]) {
ans1 += 1.0 * t[i];
} else {
dfs(f+c[i]);
ans2 += dp[f+c[i]];
ans2 += 1.0;
}
}
dp[f] = (ans1 + ans2) / n;
} int main() {
while(~scanf("%d%d", &n, &m)) {
init();
for(int i=; i<=n; i++) {
scanf("%d", &c[i]);
t[i] = (int)((1.0 + sqrt(5.0)) / * c[i] * c[i]);
}
dfs(m);
printf("%.3f\n", dp[m]);
}
return ;
}

AC

Help Me Escape ZOJ - 3640的更多相关文章

  1. Help Me Escape (ZOJ 3640)

    J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB ...

  2. 概率dp ZOJ 3640

    Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  3. ZOJ 3640 Help Me Escape:期望dp

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640 题意: 有一个吸血鬼被困住了,他要逃跑... 他面前有n条 ...

  4. zoj 3640 Help Me Escape (概率dp 递归求期望)

    题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest w ...

  5. zoj 3640 Help Me Escape 概率DP

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

  6. zoj 3640 概率dp

    题意:一只吸血鬼,有n条路给他走,每次他随机走一条路,每条路有个限制,如果当时这个吸血鬼的攻击力大于等于某个值,那么就会花费t天逃出去,否则,花费1天的时间,并且攻击力增加,问他逃出去的期望 用记忆化 ...

  7. ZOJ 3640

    很简单的概率题了 设dp[x]为能力值 为x时出去的期望 天数 #include <iostream> #include <cstdio> #include <cmath ...

  8. 概率DP

    POJ 3744 Scout YYF I 这就是一个乱搞题,暴力发现TLE了,然后看了看discuss里说可以矩阵加速,想了一会才想明白怎么用矩阵,分着算的啊.先算f[num[i]-1]之类的,代码太 ...

  9. 概率dp专场

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

随机推荐

  1. 下拉框 JComboBox,文本框JTextField

    1. 下拉框 JComboBox //导入Java类 import javax.swing.*; import java.awt.*; import java.awt.event.ActionEven ...

  2. SQL Server GUID 数据迁移至MongoDB后怎样查看?

    关键字:SQL Server NEWID():BSON:MongoDB UUID 1.遇到的问题和困惑 SQL Server中的NEWID数据存储到MongoDB中会是什么样子呢?发现不能简单的通过此 ...

  3. 通过Visual Studio 2012 比较SQL Server 数据库的架构变更

    一 需求 随着公司业务的发展,数据库实例也逐渐增多,数据库也会越来越多,有时候我们会发现正式生产数据库也测试数据库数据不一致,也有可能是预发布环境下的数据库与其他数据库架构不一致,或者,分布式数据库上 ...

  4. Nagle 算法

    1. Nagel算法        TCP/IP协议中,无论发送多少数据,总是要在数据前面加上协议头,同时,对方接收到数据,也需要发送ACK表示确认.为了尽可能的利用网络带宽,TCP总是希望尽可能的发 ...

  5. 被低估的.net(上) - 微软MonkeyFest 2018广州分享会活动回顾

    前天, 2018年11月10日, 广州图书馆\微软云开发者社区\广东职业教育信息化研究会\珠三角技术沙龙在广州图书馆负一层1号报告厅搞了一场”微软最有价值专家(MVP)广州分享会 - MonkeyFe ...

  6. eclipse设置新建jsp默认编码格式utf-8

  7. 【Teradata SQL】FALLBACK表改为NO FALLBACK表

    FALLBACK表在数据库中会留存双份数据,增加了数据可用性,但浪费了存储空间.变更表属性语句如下: alter table tab_fallback ,no fallback;

  8. 深入Ambari Metrics 机制分析

    0.简介 Ambari作为一款针对大数据平台的运维管理工具,提供了集群的创建,管理,监控,升级等多项功能,目前在业界已经得到广泛使用. Ambari指标系统( Ambari Metrics Syste ...

  9. 【css3】使用filter属性实现改变svg图标颜色

    1.兼容性: 2.应用场景:新增页面上传svg图标后,更改图标颜色后,在列表页面展示色值改后的svg图标. 3.解决方案:使用filter属性中的 drop-shadow,drop-shadow滤镜可 ...

  10. Jetson TX2(2)ubutu1604--安装opencv3.4.0

    1安装OpenCV3.4.0+contrib 1 在终端中敲入以下两句sudo rm /var/cache/apt/archives/locksudo rm /var/lib/dpkg/lock su ...