[Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】
题目链接:CF#286 - A
这场CF就这样爆零了...我真是太蒟蒻了...
题目分析
比赛的时候看到A题就发现不会,之后一直也没想出来,于是就弃了,还好不提交也不掉Rating...
比赛后看评论,看到有人说“I could not even solve the problem A, shame on me.” ,立刻就感觉到我是多么的蒟蒻...
看了评论中有人发的题解,就一句 “Normal DP”,再看了他的简单的解释,这才恍然大悟...
这道题就可以使用普通的DP,用 f[i][j] 表示走到第 i 个位置,上一步跳了 j 的距离的最大收益,直接这样做的话,i j 的范围都会是 30000 的,然而我们可以发现重要的一点, j 相对于初始跳跃距离 d 的上下波动不会超过 300 !因为假如它波动超过 300,就至少要连续跳 300 次递减或递增的距离,这个距离和一定会超过 30000,所以这个 j 的范围只要开 600 就可以了。
然后就完全是 “Normal DP” 了..
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; const int MaxN = 30000 + 5, MaxM = 600 + 5, INF = 999999999; int n, d, Ans;
int V[MaxN], f[MaxN][MaxM]; inline int gmax(int a, int b) {return a > b ? a : b;} int main()
{
scanf("%d%d", &n, &d);
int a;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
++V[a];
}
Ans = V[d];
for (int i = 0; i <= 30000; ++i) {
for (int j = 0; j <= 601; ++j) {
f[i][j] = -INF;
}
}
f[d][301] = V[d];
for (int i = d + 1; i <= 30000; ++i) {
for (int j = 1; j <= 600; ++j) {
if (i - (j - 301 + d) < 0 || i - (j - 301 + d) >= i) continue;
f[i][j] = gmax(f[i][j], f[i - (j - 301 + d)][j]);
f[i][j] = gmax(f[i][j], f[i - (j - 301 + d)][j + 1]);
f[i][j] = gmax(f[i][j], f[i - (j - 301 + d)][j - 1]);
f[i][j] += V[i];
Ans = gmax(Ans, f[i][j]);
}
}
printf("%d\n", Ans);
return 0;
}
[Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】的更多相关文章
- 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【考虑可用范围】
题目链接:http://codeforces.com/problemset/problem/505/C 题意: 有n个宝石,分别在位置p[i].(1 <= n,p[i] <= 30000) ...
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
题意:有30001个岛,在一条线上,从左到右编号一次为0到30000.某些岛屿上有些宝石.初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d.如果当前他跳跃的距离为L,他下一次跳跃的距离只能为 ...
- 505C Mr. Kitayuta, the Treasure Hunter
传送门 题目大意 一共有30000个位置,从第0个位置开始走,第一次走k步,对于每一次走步,可以走上一次的ki+1 ,ki ,ki-1步数(必须大于等于1),每个岛上有value,求最大能得到的val ...
- cf 506 A. Mr. Kitayuta, the Treasure Hunter
不知道这个sb题怎么做错了.. /*#include <bits/stdc++.h> #define LL long long using namespace std; inline in ...
随机推荐
- windows下 tomcat7 配置成服务
最简单方法:下载windows安装版,下一步下一步搞定! 非安装版: 1.下载tomcat7 windows版 2.首先找到F:\apache\bin\service.bat(不同的计算机Tomcat ...
- 手机相机ISO是什么
要说什么是ISO还要从传统胶片相机说起,ISO被 称为感光度,它是衡量传统相机所使用胶片感光速度的国际统一指标,其数值反映了胶片感光时的速度(其实是银元素与光线的光化学反应速率).而对于现在并不 使用 ...
- 一个备份MySQL数据库的简单Shell脚本(转)
Shell脚本是我们写不同类型命令的一种脚本,这些命令在这一个文件中就可以执行.我们也可以逐一敲入命令手动执行.如果我们要使用shell脚本就必须在一开始把这些命令写到一个文本文件中,以后就可以随意反 ...
- URAL 1062 - Triathlon(半平面交)
这个题乍眼一看好像很简单,然后我就认为u.v.w只要有全部比另外一个人小的就不能win,否则就能win,但是这个思路只对了一半 不能win的结论是正确的,但是win的结论不止排除这一个条件 将这个人与 ...
- UITableView beginUpdate和endUpdate使用的前提
转载地址:http://blog.csdn.net/vieri_ch/article/details/46893023 UITableView有两个方法,用于单元格动画变化的方法,beginUpdat ...
- alloc、init你弄懂50%了吗?
前言 这是一篇我记录对alloc.init分析思考的笔记.如果读者想看懂我的第二个思考,可能需要您至少了解内存的分段分页管理,如果您对其一点都不知道,可以先看这篇软文简单了解一下.另外很重要的一点是, ...
- 他们都没告诉你适配 Android N 需要注意什么
还记得 6.0 对 Apache Http 库的废除导致的应用崩溃吗?还记得 6.0 中 MAC id 始终返回为空导致的唯一 id 混合生成算法大幅失效吗? 1. Android 中 Java 的实 ...
- JS的事件监听机制
很久以前有个叫Netscape的姑娘,她制订了Javascript的一套事件驱动机制(即事件捕获) 后来又有一个叫“IE”的小子,这孩子比较傲气,他认为“凭什么我要依照你的规则走”,于是他又创造了一套 ...
- 【IBM】Merlin 给 Java 平台带来了非阻塞 I/O
Merlin 给 Java 平台带来了非阻塞 I/O 新增的功能大幅降低了线程开销 Java 技术平台早就应该提供非阻塞 I/O 机制了.幸运的是,Merlin(JDK 1.4)有一根几乎在各个场合都 ...
- python----------进程、线程、协程
进程与线程 什么是进程(process)? An executing instance of a program is called a process. Each process provides ...