【题目链接】:http://codeforces.com/problemset/problem/505/C

【题意】



一开始你跳一步长度为d;

之后你每步能跳d-1,d,d+1这3种步数;

然后在路上有很多个位置有treasure;

问你,你最多能获得多少个treasure;

最远跳到30000

【题解】



记忆化搜索;

设dp[x][y]表示跳到第x个位置了;

然后前一步跳的步数为d+y能够获得的最多treasure个数;

这里y能够为负值;且d+y>0;

这里用和d的差值作为第二维是因为;

1+2+3…+n=(1+n)*n/2

然后令其等于30000的话;

可以发现,最大的差值应为250左右,不可能更大了;

因为即使每一步都是递增的,然后d=0,也能够满足在差值为250就跳出边界;

因此用差值来作为第二维是正确的选择>_<

然后因为差值能为负值;

所以在写的时候,第二维加个偏移量就好;



【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 3e4+100;
const int py = 250; int n, d,num[N];
int f[N][600]; int dfs(int x, int l)
{
//cout << x << ' '<<l << endl;
if (x > 30000) return 0;
if (f[x][l+py] != -1)
return f[x][l+py];
int temp = 0;
rep1(i, -1, 1)
{
if (d + l + i <= 0) continue;
int y = x + d + l + i;
temp = max(temp, num[x] + dfs(y, l + i));
}
return f[x][l+py] = temp;
} int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
ms(f, -1);
cin >> n >> d;
rep1(i, 1, n)
{
int x;
cin >> x;
num[x]++;
}
cout << dfs(d, 0) << endl;
return 0;
}

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

  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. 【codeforces 505D】Mr. Kitayuta's Technology

    [题目链接]:http://codeforces.com/problemset/problem/505/D [题意] 让你构造一张有向图; n个点; 以及所要求的m对联通关系(xi,yi) 即要求这张 ...

  3. 【Codeforces 506E】Mr.Kitayuta’s Gift&&【BZOJ 4214】黄昏下的礼物 dp转有限状态自动机+矩阵乘法优化

    神题……胡乱讲述一下思维过程……首先,读懂题.然后,转化问题为构造一个长度为|T|+n的字符串,使其内含有T这个子序列.之后,想到一个简单的dp.由于是回文串,我们就增量构造半个回文串,设f(i,j, ...

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

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

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

  6. 【codeforces 255D】Mr. Bender and Square

    [题目链接]:http://codeforces.com/problemset/problem/255/D [题意] 给你一个n*n的方框; 给你一个方块;(以下说的方块都是单位方块) 每一秒钟,可以 ...

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

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

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

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

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

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

随机推荐

  1. kmp变形,带通配符的kmp——华科校赛E 好题

    https://blog.csdn.net/a302549450/article/details/80948741?tdsourcetag=s_pctim_aiomsg 上面是题解的链接.., 其实和 ...

  2. text-html 转译

    var HtmlUtil = { 2 /*1.用浏览器内部转换器实现html编码(转义)*/ 3 htmlEncode:function (html){ 4 //1.首先动态创建一个容器标签元素,如D ...

  3. https://www.cnblogs.com/chinabin1993/p/9848720.html

    转载:https://www.cnblogs.com/chinabin1993/p/9848720.html 这段时间一直在用vue写项目,vuex在项目中也会依葫芦画瓢使用,但是总有一种朦朦胧胧的感 ...

  4. Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-config:jar:unk

    <dependencyManagement> <dependencies> <dependency> <groupId>org.springframew ...

  5. 20.multi_协程方法抓取总阅读量

    # 用asyncio和aiohttp抓取博客的总阅读量 (提示:先用接又找到每篇文章的链接) # https://www.jianshu.com/u/130f76596b02 import re im ...

  6. linq to sql any和all的区别

    Any说明:用于判断集合中是否有元素满足某一条件:不延迟.(若条件为空,则集合只要不为空就返回True,否则为False).1.简单形式:仅返回没有订单的客户:var q =from c in db. ...

  7. 谈谈HINT /*+parallel(t,4)*/在SQL调优中的重要作用

    /*+parallel(t,4)*/在大表查询等操作中能够起到良好的效果,基于并行查询要启动并行进程.分配任务与系统资源.合并结果集,这些都是比较消耗资源,但我们为能够减少执行事务的时间使用paral ...

  8. CF755F PolandBalls and Gifts

    题意:给你一个礼物的置换.有k个人忘带了礼物.一个人无法获得礼物为他自己没有带礼物或给他带礼物的那个人没有带礼物.求选择k个人,没有获得礼物的人数的最小值和最大值. n,k<=1e6. 标程: ...

  9. DMZ在虚拟化环境中的部署

    常见的方法有三种: 1.分别部署 2.部分虚拟化 3.全部虚拟化 传统DMZ部署结构: 分别部署: 想要保持DMZ区域物理隔离采用这种方法,每个区域分别部署进入不同的服务器集群,区域之间的连接采用物理 ...

  10. [转]C#的扩展方法解说

    C#的扩展方法解说 扩展方法的目的就是为一个现有类型添加一个方法,现有类型既可以是int,string等数据类型,也可以是自定义的数据类型. 为数据类型的添加一个方法的理解:一般来说,int数据类型有 ...