codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
题意:有30001个岛,在一条线上,从左到右编号一次为0到30000。某些岛屿上有些宝石。初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d。如果当前他跳跃的距离为L,他下一次跳跃的距离只能为L-1,L,L+1之一且不能为0。他只能往编号更大的岛跳,直到他不能跳,问他最多能收集多少个宝石?
思路:用dp[i][j]表示在第i个岛,上一步跳的距离为j的收集到的最多宝石的个数。这样如果直接表示的话,j最大可能是30000,空间会超,但是所跳跃的距离不会超过d+250, 因为额1+2+3+...+250>30000, 所以如果用偏移量来表示的话,就可以了,dp[i][j]表示在第i个岛,上一步的跳跃的距离为j-250+d,其中d-250算是一个偏移量,因为如果直接用d表示的话,那么如果d减少1,就会出现负数,加上250的偏移就不会是负数了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ;
int num[maxn];
int dp[maxn][];
int main()
{
int n, d, p;
scanf("%d%d", &n, &d);
int Max = ;
for (int i = ; i < n; i++)
{
scanf("%d", &p);
num[p]++;
Max = max(Max, p);
}
memset(dp, -, sizeof(dp));
dp[d][] = num[d];
int ans = ;
for (int i = d; i <= Max; i++)
{
for (int j = ; j <= ; j++)
{
if (dp[i][j] != -)//判断第i个岛是否可达,如果可达,才可以进行往后转移(也就是往后跳)
{
ans = max(ans, dp[i][j]);
int step = j - + d;
if (i + step <= Max)//这里不用判断step>0,因为能进来,肯定是满足的step>0的。
dp[i + step][j] = max(dp[i + step][j], dp[i][j] + num[i + step]);
if (step - > && i + step - <= Max)
dp[i + step - ][j - ] = max(dp[i + step - ][j - ], dp[i][j] + num[i + step - ]);
if (i + step + <= Max)
dp[i + step + ][j + ] = max(dp[i + step + ][j + ], dp[i][j] + num[i + step + ]);
}
}
}
printf("%d\n", ans);
return ;
}
codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)的更多相关文章
- [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 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 Round #286 Div.1 A Mr. Kitayuta, the Treasure Hunter --DP
题意:0~30000有30001个地方,每个地方有一个或多个金币,第一步走到了d,步长为d,以后走的步长可以是上次步长+1,-1或不变,走到某个地方可以收集那个地方的财富,现在问走出去(>300 ...
- 505C Mr. Kitayuta, the Treasure Hunter
传送门 题目大意 一共有30000个位置,从第0个位置开始走,第一次走k步,对于每一次走步,可以走上一次的ki+1 ,ki ,ki-1步数(必须大于等于1),每个岛上有value,求最大能得到的val ...
- 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter
[题目链接]:http://codeforces.com/problemset/problem/505/C [题意] 一开始你跳一步长度为d; 之后你每步能跳d-1,d,d+1这3种步数; 然后在路上 ...
- [Codeforces Round#286] A.Mr. Kitayuta, the Treasure Hunter 【Normal DP..】
题目链接:CF#286 - A 这场CF就这样爆零了...我真是太蒟蒻了... 题目分析 比赛的时候看到A题就发现不会,之后一直也没想出来,于是就弃了,还好不提交也不掉Rating... 比赛后看评论 ...
- cf 506 A. Mr. Kitayuta, the Treasure Hunter
不知道这个sb题怎么做错了.. /*#include <bits/stdc++.h> #define LL long long using namespace std; inline in ...
随机推荐
- 几个RTP的开源实现
玩了两天rtp协议,基本把rtsp/rtcp/rtp/rtmp/srtp/strcp/mms,几个协议的区别和概念弄明白了. 这里记录一下. rtsp:类似用户界面操作,和Http比较类似,提供播放, ...
- SPRING IN ACTION 第4版笔记-第二章Wiring Beans-005-<constructor-arg>和c-namespace
1. package soundsystem; public class SgtPeppers implements CompactDisc { private String title = &quo ...
- 从tcp原理角度理解Broken pipe和Connection reset by peer的区别
从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...
- linux下包管理命令yum与apt-get以及开发环境配置
一般来说市面上常见的Linux系统分为两大类: RH类:Redhat.centOS和Fedora等 Debian类:ubuntu.Debian等. 上述两类系统对应的包管理工具命令分别是yum和apt ...
- (转载)Chrome 快捷键 整理版
(转载)http://www.douban.com/group/topic/13802153/ chrome窗口和标签页快捷键: Ctrl+N 打开新窗口 Ctrl+T 打开新标签页 Ctrl+Shi ...
- PHP中 magic_quotes_gpc 和 magic_quotes_runtime 区别及其反斜线转义问题
php中关于反斜线转义: php中数据的魔法引用函数 magic_quotes_gpc 或 magic_quotes_runtime 设置为on时,当数据遇到 单引号' 和 双引号" ...
- Python串口操作纸币器1
公司需要纸币器开发,参考纸币器文档和网上的一篇vb版本,代码如下: # -*- coding:utf-8 -*- # Author: Pete Yim<xpHook@gmail.com> ...
- Educational Codeforces Round 3
A. USB Flash Drives 水题,排序即可 ]; int main() { int n,m; scanf("%d%d",&n,&m); ;i<n; ...
- html自定义checkbox、radio、select —— select篇
上一篇<html自定义checkbox.radio.select —— checkbox.radio篇>介绍了我们是怎么将 html 自带的 checkbox.radio 改成我们自定义的 ...
- c#复制图片到粘贴板
string fielN; private void button1_Click(object sender, EventArgs e) { OpenFileDialog saveFileDialog ...