CF505C Mr. Kitayuta, the Treasure Hunter
题目
见链接。
题解
知识点:线性dp。
常规的状态 \(dp[i][j]\) 表示为到第 \(i\) 个岛上一步走了 \(j\) 能得到宝藏的最大值,会炸空间。注意到步数是就算从 \(1\) 开始走到结束,最多不会超过初始步数 \(d\) 的 \(\pm 250\) 。因此,改变状态为到第 \(i\) 个岛上一步的关于 \(d\) 的偏移量为 \(j+300\) (负数不能表示,所以整体加 \(300\))。
遍历 \(j\) 时要注意边界条件,如步数 \(d+j-300 \geq 1\) ,上一次的岛屿编号 \(i-(d+j-300) \geq 1\) 。
初始位置的宝藏要初始化进去,其他应该是负无穷。
答案不一定在最后一个岛上,因为可能跳不到,所以考虑在过程中取最大值即可。
时间复杂度 \(O(30000*600)\)
空间复杂度 \(O(30000*600)\)
代码
#include <bits/stdc++.h>
using namespace std;
int dp[30007][607];
int p[30007];
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, d;
cin >> n >> d;
for (int i = 1, tmp;i <= n;i++) cin >> tmp, p[tmp]++;
memset(dp, -0x3f, sizeof(dp));
dp[d][300] = p[d];
int ans = p[d];
for (int i = d + 1;i <= 30000;i++) {
for (int j = 10;j <= 590;j++) {///偏移量不超过±250
if (1 <= d + j - 300 && i - (d + j - 300) >= 1) {///步数不小于1,岛屿不小于1
dp[i][j] = max({
dp[i - (d + j - 300)][j - 1],
dp[i - (d + j - 300)][j],
dp[i - (d + j - 300)][j + 1]
}) + p[i];
}
ans = max(dp[i][j], ans);///有可能跳不到30000而直接超过30000,但一定能经过最大值路径上的岛屿,每次保存最大值即可
///因为终点未知,也可以考虑逆推,因为起点固定
}
}
cout << ans << '\n';
return 0;
}
CF505C Mr. Kitayuta, the Treasure Hunter的更多相关文章
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)
题目链接: C. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 me ...
- Codefores 506A Mr. Kitayuta, the Treasure Hunter( DP && dfs )
A. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 megabyte ...
- [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter
Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...
- 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter
[题目链接]:http://codeforces.com/problemset/problem/505/C [题意] 一开始你跳一步长度为d; 之后你每步能跳d-1,d,d+1这3种步数; 然后在路上 ...
- Codeforces Round #286 Div.1 A Mr. Kitayuta, the Treasure Hunter --DP
题意:0~30000有30001个地方,每个地方有一个或多个金币,第一步走到了d,步长为d,以后走的步长可以是上次步长+1,-1或不变,走到某个地方可以收集那个地方的财富,现在问走出去(>300 ...
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
题意:有30001个岛,在一条线上,从左到右编号一次为0到30000.某些岛屿上有些宝石.初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d.如果当前他跳跃的距离为L,他下一次跳跃的距离只能为 ...
- [Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】
题目链接:CF#286 - A 这场CF就这样爆零了...我真是太蒟蒻了... 题目分析 比赛的时候看到A题就发现不会,之后一直也没想出来,于是就弃了,还好不提交也不掉Rating... 比赛后看评论 ...
- 505C Mr. Kitayuta, the Treasure Hunter
传送门 题目大意 一共有30000个位置,从第0个位置开始走,第一次走k步,对于每一次走步,可以走上一次的ki+1 ,ki ,ki-1步数(必须大于等于1),每个岛上有value,求最大能得到的val ...
- Codeforces 505C Mr. Kitayuta, the Treasure Hunter:dp【考虑可用范围】
题目链接:http://codeforces.com/problemset/problem/505/C 题意: 有n个宝石,分别在位置p[i].(1 <= n,p[i] <= 30000) ...
- cf 506 A. Mr. Kitayuta, the Treasure Hunter
不知道这个sb题怎么做错了.. /*#include <bits/stdc++.h> #define LL long long using namespace std; inline in ...
随机推荐
- Python注释是什么东东
注释 标注解释,目的是帮助读者理解的文本 也就是说,注释首先是文本,其二是说明,其三是思路,其四是例子注释有两种形式 1. # ... 单行注释 用于对某句语句或语句块进行解释 放在语句块的头行或一个 ...
- K8s集群CoreDNS监控告警最佳实践
本文分享自华为云社区<K8s集群CoreDNS监控告警最佳实践>,作者:可以交个朋友. 一 背景 coreDNS作为K8s集群中的关键组成部分.主要负责k8s集群中的服务发现,域名解析等功 ...
- [转帖]SecurityProtocolType 枚举
https://learn.microsoft.com/zh-cn/dotnet/api/system.net.securityprotocoltype?view=net-8.0 命名空间: Syst ...
- [转帖]tidb之旅——tidb架构选择
https://zhuanlan.zhihu.com/p/641650168 前言 从4月份开始利用tidb改造了我们公司bi系统.这个过程中,我感觉到了tidb的强大.也打算记录一下整个改造过程.我 ...
- [转帖]十大主流Nehalem服务器横评(多图)
https://server.51cto.com/article/201820.html 作者:佚名2010-05-25 09:52:27 运维服务器运维 除了我们的两台基准服务器之外,本次横向评测活 ...
- [转帖]Linux性能优化(十五)——CPU绑定
一.孤立CPU 1.孤立CPU简介 针对CPU密集型的任务,CPU负载较高,推荐设置CPU Affinity,以提高任务执行效率,避免CPU进行上下文切换,提高CPU Cache命中率. 默认情况下, ...
- [转帖]Shell中常用的date时间命令
常用FORMAT %Y YYYY格式的年份(Year) %m mm格式的月份(),01-12 %d dd格式的日期(day of month),01-31 %H HH格式的小时数(),00 ...
- [转帖]windows使用net user add用户并加入管理员,从而支持rdp远程登陆访问
C:\phpstudy_pro\WWW> net user test2 /add 命令成功完成. C:\phpstudy_pro\WWW> net user test2 Huawei ...
- [转帖]jar启动指定JDK/JRE 安装路径教程
https://blog.csdn.net/weixin_40986713/article/details/128136777 前言 因为疫情在家办公的缘故,有个老项目,需要改个接口,然后需要前端联调 ...
- 【网络流,dp】Gym102220A Apple Business
Problem Link 有一棵 \(n\) 个点的完全二叉树(点 \(i\) 的父亲是 \(\lfloor i/2\rfloor\)),第 \(i\) 个点有 \(a_i\) 个苹果.现在有 \(m ...