codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)
题目链接:
C. Mr. Kitayuta, the Treasure Hunter
1 second
256 megabytes
standard input
standard output
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.
Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:
- First, he will jump from island 0 to island d.
- After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.
Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.
The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.
The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.
Print the maximum number of gems that Mr. Kitayuta can collect.
4 10
10
21
27
27
3
8 8
9
19
28
36
45
55
66
78
6
13 7
8
8
9
16
17
17
18
21
23
24
24
26
30
4 题意: 有30000个点,n个点放在pi上,第一次去d,每次走的距离只能为上次行走的距离l,l+1,l-1,但是一定要前进;问最后能得到的最大值是多少; 思路: 可以发现行走长度的变化范围不超过250;dp[i][j]表示走j长到达i能得到的最大值;转移方程看代码吧; AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e4+;
const int N=3e4;
const int inf=;
int n,d;
int p[maxn],num[maxn],dp[maxn][];
int main()
{
scanf("%d%d",&n,&d);
for(int i=;i<=n;i++)
{
scanf("%d",&p[i]);
num[p[i]]++;
}
memset(dp,-inf,sizeof(dp));
dp[d][]=num[d];
for(int i=;i<=N;i++)
{
for(int j=;j<=;j++)
{
int x=j-+d;
if(i+x>i&&i+x<=N)dp[i+x][j]=max(dp[i+x][j],dp[i][j]+num[i+x]);
if(i+x+>i&&i+x+<=N)dp[i+x+][j+]=max(dp[i+x+][j+],dp[i][j]+num[i+x+]);
if(i+x->i&&i+x-<=N)dp[i+x-][j-]=max(dp[i+x-][j-],dp[i][j]+num[i+x-]);
}
}
int ans=;
for(int i=;i<=N;i++)
{
for(int j=;j<=;j++)
{
ans=max(ans,dp[i][j]);
}
}
cout<<ans<<"\n"; }
codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)的更多相关文章
- 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter
[题目链接]:http://codeforces.com/problemset/problem/505/C [题意] 一开始你跳一步长度为d; 之后你每步能跳d-1,d,d+1这3种步数; 然后在路上 ...
- 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(dp)
题意:有30001个岛,在一条线上,从左到右编号一次为0到30000.某些岛屿上有些宝石.初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d.如果当前他跳跃的距离为L,他下一次跳跃的距离只能为 ...
- 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
Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...
- Codeforces 505C Mr. Kitayuta, the Treasure Hunter:dp【考虑可用范围】
题目链接:http://codeforces.com/problemset/problem/505/C 题意: 有n个宝石,分别在位置p[i].(1 <= n,p[i] <= 30000) ...
- [Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】
题目链接:CF#286 - A 这场CF就这样爆零了...我真是太蒟蒻了... 题目分析 比赛的时候看到A题就发现不会,之后一直也没想出来,于是就弃了,还好不提交也不掉Rating... 比赛后看评论 ...
- 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 ...
随机推荐
- Google解决跨域
1.添加 --disable-web-security --user-data-dir=D:\tmp 2.在D的根目录新建tmp文件夹
- django cookie session操作
Cookie是什么? cookie说的直白点就是保存在用户浏览器端的一个键值对,举个例子,你现在登录了京东商城,你把浏览器关闭之后,你再打开京东,你还是可以对你的账户继续操作,已经购买的商品,订单都是 ...
- Codeforces 655E Beautiful Subarrays【01trie树】
题目链接: http://codeforces.com/contest/665/problem/E 题意: 求异或值大于给定K的区间个数. 分析: 首先我们可以得到区间前缀的异或值. 这样我们将这个前 ...
- Struts2防止重复提交
一般使用<interceptor-ref name="token"></interceptor-ref>或者<interceptor-ref name ...
- Building a Radio Listening Station to Decode Digital Audio & Police Dispatches
On April 7, 2017, residents in Dallas, Texas, woke to the sound of emergency sirens blaring all over ...
- 如何快速的开发一个完整的iOS直播app(美颜篇)
前言 在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播app(原理篇) 开发一款直播app,美颜功能是很重要的,如果没有美颜功能,可能分分钟钟掉粉千万,本篇主要讲 ...
- BUPT复试专题—寻找第 K 小的数(2009)
题目描述 给你 n 个完全不相同整数(n<=300),每一个数都大于 0 并且小于 1000,请找出 第 k 小的数. 输入 输入包括两行,第一行用空格隔开的两个数 n 和 k;第二行有 n 个 ...
- fuel 安装openstack
- 【JavaScript】数据类型
学习不论什么一种程序设计语言.数据类型都是不可缺少的一部分内容,非常基础,也非常重要.该用何种数据类型定义变量.这也是编程中最基础的一项. ECMAScript中有5种简单数据类型:Undefined ...
- ssh命令、ping命令、traceroute 命令所使用的协议
在Node reboot or eviction: How to check if yourprivate interconnect CRS can transmit network heartbea ...