传送门

题目大意

一共有30000个位置,从第0个位置开始走,第一次走k步,对于每一次走步,可以走上一次的ki+1 ,ki ,ki-1步数(必须大于等于1),每个岛上有value,求最大能得到的value能有多少。

分析

首先我们不难想到dpij表示走到第i个位置,上次走的步数为j,然而30000*30000时间复杂度和空间复杂度都会爆炸,所以我们考虑如何优化掉一维,然而我们发现是无法优化掉一维的。

但由于一个只有30000个位置,所有我们想到上次走的步数的所有可能情况可能不是很多,由式子d+(d+1)+(d+2)+…+(d+maxl)≤30000可得maxl大致是250,也就是说上次走的步数最少是d-250,最多是d+250.于是我们得到dpij,其中i表示考虑到第i个位置,j表示上次走的长度-d,注意为了防止数组出现负数我们将第二维统一加上maxl。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl;
const int inf=1e9+;
int dp[][],maxl=,cnt[],N=;
int main(){
int n,m,i,j,k,d;
scanf("%d%d",&n,&d);
for(i=;i<=n;i++)scanf("%d",&m),cnt[m]++;
for(i=;i<=N;i++)for(j=;j<=;j++)dp[i][j]=-inf;
dp[d][maxl]=cnt[d]+cnt[];
for(i=d;i<N;i++)for(j=-maxl;j<=maxl;j++)if(dp[i][j+maxl]!=-inf){
if(i+j+d<=N&&j+d>)
dp[i+j+d][j+maxl]=max(dp[i+j+d][j+maxl],dp[i][j+maxl]+cnt[i+j+d]);
if(j+d->&&i+j+d-<=N&&j->=-maxl)
dp[i+j+d-][j-+maxl]=max(dp[i+j+d-][j-+maxl],dp[i][j+maxl]+cnt[i+j+d-]);
if(j+d+>&&i+j+d+<=N&&j+<=maxl)
dp[i+j+d+][j++maxl]=max(dp[i+j+d+][j++maxl],dp[i][j+maxl]+cnt[i+j+d+]);
}
int ans=;
for(i=;i<=N;i++)for(j=-maxl;j<=maxl;j++)ans=max(ans,dp[i][j+maxl]);
cout<<ans<<endl;
return ;
}

505C Mr. Kitayuta, the Treasure Hunter的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  8. [Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】

    题目链接:CF#286 - A 这场CF就这样爆零了...我真是太蒟蒻了... 题目分析 比赛的时候看到A题就发现不会,之后一直也没想出来,于是就弃了,还好不提交也不掉Rating... 比赛后看评论 ...

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

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

随机推荐

  1. C++string类整理

    string类 string类 头文件:#include<string> 名称空间:using namespace std; 初始化: string Str; String类的构造函数和析 ...

  2. CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)

    Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...

  3. java 实现拖动文件到窗口功能

    package tuo; import java.awt.BorderLayout; import java.awt.Color; import java.awt.datatransfer.DataF ...

  4. XML数据库的尝试

    首先祝大家新年快乐.身体健康,平安就是福气. 对于一般的个人迷你项目,数据量不大的时候,完全没有必要使用数据库,管理数据使用XML就可以了. 自己尝试写了一个XML数据库,插入1w条小记录,大概3M大 ...

  5. 横向排列两个多个div盒子的方法(CSS浮动清除float-clear/inline)/办法

    最近在做一个div css切割,昨晚发现了长期以来一直无记录下来的问题!关于兼容IE跟FF的float属性.趁现在还清醒赶紧记下笔记先:一.并排在一行的两个div样式有这种情况:ie或者ff下对于子d ...

  6. python基础准备

    老男孩python全栈学习day1 第一讲python基础: 1.python起源:python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中 ...

  7. IE版本的标准定义

    解决方案 首页加代码把IE浏览器的标准改了,无论客户用的什么IE,都是按照IE7的标准来的. <meta http-equiv="X-UA-Compatible" conte ...

  8. CodeForces - 510B Fox And Two Dots (bfs或dfs)

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. AngularJS:SQL

    ylbtech-AngularJS:SQL 1.返回顶部 1. AngularJS SQL 在前面章节中的代码也可以用于读取数据库中的数据. 使用 PHP 从 MySQL 中获取数据 AngularJ ...

  10. Python模块之: ConfigParser 配置文件读取

    Python模块之: ConfigParser 配置文件读取   ConfigParser用于读写类似INI文件的配置文件,配置文件的内容可组织为组,还支持多个选项值(option-value)类型. ...