传送门

题目大意

一共有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. commons-dbcp连接池的使用

    数据库连接池 池参数(所有池参数都有默认值): 初始大小: 最小空闲连接数: 增量:一次创建的最小单位(5个) 最大空闲连接数:12个 最大连接数:20个 最大的等待时间:1000毫秒 四大连接参数: ...

  2. 数组中累加和为k的最大子数组的长度

    package com.hzins.suanfa; import java.util.HashMap; public class demo { /** * 数组中累加和为k的最大子数组的长度 * @p ...

  3. Office 2007在安装过程中出错

    1, 可能是因为c:\program files\common files\microsoft Shared\web server Extensions\40\bin目录下缺少Fp4autl.dll, ...

  4. wordpress 插件 汉化

    http://blog.wpjam.com/article/localizing-a-wordpress-plugin-using-poedit/ 翻译或者说本地化 WordPress 插件和主题可以 ...

  5. 《zero to one》读后感

    五一放假,赶上下雨,天气很凉爽,这种天气很舒服,不冷不热,听着滴答的雨声,看看书其实也不错. 约了两个同学吃了顿饭,然后决定窝在实验室了,最近看了彼得.蒂尔的<zero to one>,确 ...

  6. linux中使用opdir_readdir读取目录中的信息

    #include <dirent.h>#include <stdio.h>#include <stdlib.h> int main(int argc, char * ...

  7. itext生成pdf(附带页眉,页脚,页码)

    package cn.picclife.mwx.salesupport.marketactivity.util; import java.io.File; import java.io.FileOut ...

  8. Milking Time(DP)

    个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和 d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此 ...

  9. 图的m着色问题 (回溯搜索)

    图的m着色问题 [问题描述]        给定无向连通图G和m种不同的颜色.用这些颜色为图G的各顶点着色,每个顶点着一种颜色.如果有一种着色法使G中每条边的2个顶点着不同颜色,则称这个图是m可着色的 ...

  10. oracle如何insert into 多个values

    稍微熟悉Oracle的都知道,如果我们想一条SQL语句向表中插入多个值的话,如果如下语句 INSERT INTO 某表 VALUES(各个值),VALUES(各个值),.....; 这样会报错的,因为 ...