[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 ...
随机推荐
- ASP.NET常用导出Excel方法汇总
本文转载:http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html http://geekswithblogs.net/a ...
- Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead
“Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(B ...
- 【MongoDB】在windows平台下mongodb的分片集群(五)
本篇接着上面的四篇继续讲述在window平台下mongodb的分片集群搭建. 在分片集群中也照样能够创建索引,创建索引的方式与在单独数据库中创建索引的方式一样.因此这不再多说.本篇主要聚焦在分片键的选 ...
- [Reactive Programming] Using an event stream of double clicks -- buffer()
See a practical example of reactive programming in JavaScript and the DOM. Learn how to detect doubl ...
- javascript,jquery(闭包概念)(转)
偶尔听人说javascript闭包,让我联想起以前学编译原理和数字逻辑里讲的闭包,以前上课讲的闭包很难懂,而且含有递归的意思在里面,现在不想再查看里面的闭包概念. 但javascript我是经常要用, ...
- 使用org.apache.jasper.JspC编译jsp文件--转载
JspC可以通过jspc.setArgs(args);设置所需参数,和使用指令进行编译相同, 使用指令编译范例: java -cp jasper.jar;servlet-api.jar;Fcatali ...
- Map 迭代 两种方法
Map 迭代 两种方法 Map<String, String> map=new HashMap<String,String>(); map.put("1", ...
- 利用jpedal进行pdf转换成jpeg,jpg,png,tiff,tif等格式的图片
项目中运用到pdf文件转换成image图片,开始时使用pdfbox开源库进行图片转换,但是转换出来的文件中含有部分乱码的情况.下面是pdfBox 的pdf转换图片的代码示例. try{ String ...
- wampserver 2.4 配置虚拟主机
最近用到了wamp环境,想创建一个虚拟主机,可是忘记了,于是百度了一下,把它写下来: 环境wampserver 2.4 找到安装目录,进入apache安装目录:找到conf 下的 httpd.conf ...
- selenium+eclipse+python环境
1.下载并安装jdk,配置环境变量: 2.下载并安装python,配置path系统环境变量:D:\Program Files\python34: 3.安装selenium,在安装好的python路径D ...