题目链接: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..】的更多相关文章

  1. 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 ...

  2. 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 ...

  3. [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter

    Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...

  4. 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter

    [题目链接]:http://codeforces.com/problemset/problem/505/C [题意] 一开始你跳一步长度为d; 之后你每步能跳d-1,d,d+1这3种步数; 然后在路上 ...

  5. Codeforces Round #286 Div.1 A Mr. Kitayuta, the Treasure Hunter --DP

    题意:0~30000有30001个地方,每个地方有一个或多个金币,第一步走到了d,步长为d,以后走的步长可以是上次步长+1,-1或不变,走到某个地方可以收集那个地方的财富,现在问走出去(>300 ...

  6. Codeforces 505C Mr. Kitayuta, the Treasure Hunter:dp【考虑可用范围】

    题目链接:http://codeforces.com/problemset/problem/505/C 题意: 有n个宝石,分别在位置p[i].(1 <= n,p[i] <= 30000) ...

  7. codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)

    题意:有30001个岛,在一条线上,从左到右编号一次为0到30000.某些岛屿上有些宝石.初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d.如果当前他跳跃的距离为L,他下一次跳跃的距离只能为 ...

  8. 505C Mr. Kitayuta, the Treasure Hunter

    传送门 题目大意 一共有30000个位置,从第0个位置开始走,第一次走k步,对于每一次走步,可以走上一次的ki+1 ,ki ,ki-1步数(必须大于等于1),每个岛上有value,求最大能得到的val ...

  9. cf 506 A. Mr. Kitayuta, the Treasure Hunter

    不知道这个sb题怎么做错了.. /*#include <bits/stdc++.h> #define LL long long using namespace std; inline in ...

随机推荐

  1. 学习了几天的jQuery Mobile的一点感受

    一.Write less  Do more! 这好像就是jQuery Mobile的口号吧.基于jQuery类库的jQuery Mobile移动web插件,有了这个轻量级插件后,排版方便了许多,很多样 ...

  2. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(6)-Unity 2.x依赖注入by运行时注入[附源码]

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(6)-Unity 2.x依赖注入by运行时注入[附源码] Unity 2.x依赖注入(控制反转)IOC,对 ...

  3. HP P2055d激光打印机PCL XL error的解决

    近日,于客户处安装HP P2055d激光打印机(2009年11月份生产的机器),介绍下硬件环境:PC:Dell OptiPlex 360,另有一台富士通DPK 8600E票据打印机,P2055d通过U ...

  4. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  5. [Javascript] An Introduction to JSPM (JavaScript Package Manager)

    JSPM can handle installed packages, transpiling ES6, and bundling all from the command-line. This vi ...

  6. 腾讯QQ企业邮箱POP3/SMTP设置

    腾讯企业邮箱支持通过client进行邮件管理. POP3/SMTP协议 收发邮件server地址分别例如以下. 接收邮件server:pop.exmail.qq.com (port 110) 发送邮件 ...

  7. 实例详解 EJB 中的六大事务传播属性--转

    前言 事务 (Transaction) 是访问并可能更新数据库中各种数据项的一个程序执行单元 (unit).在关系数据库中,一个事务可以是一条或一组 SQL 语句,甚至整个程序.它有通常被称为 ACI ...

  8. DIV------使用 <div> 元素的网页布局

    <!DOCTYPE html> <html> <head> <style type="text/css"> div#containe ...

  9. HDFS的Java客户端操作代码(查看HDFS下所有的文件存储位置信息)

    1.查看HDFS下所有的文件存储位置信息 package Hdfs; import java.net.URI; import org.apache.hadoop.conf.Configuration; ...

  10. memcached并发处理

    memcached(十八)并发原语CAS与GETS操作 Memcached 并发控制 CAS 协议 memcache控制高并发问题 使用memcached进行并发控制 memcached的最佳实践方案