【DP】 Codeforces Round #286 A - Mr. Kitayuta, the Treasure Hunter
来源:互联网 发布:nba2k17人物捏脸数据 编辑:程序博客网 时间:2024/04/29 16:01
注意到步数的改变量最多为250,然后就是简单DP了。。。。
#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 100000#define maxm 10005#define eps 1e-10#define mod 1000000007#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define pii pair<int, int>//#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headint a[maxn];int dp[maxn][505];int n, d;void read(void){int x;scanf("%d%d", &n, &d);for(int i = 1; i <= n; i++) scanf("%d", &x), a[x]++;}void work(void){dp[d][250] = 1 + a[d];int ans = 0;for(int i = 1; i <= 30000; i++) {for(int j = 0; j <= 500; j++) {if(!dp[i][j]) continue;int t = j - 250 + d;ans = max(ans, dp[i][j]);if(t == 1) {dp[i+t][j] = max(dp[i+t][j], dp[i][j] + a[i+t]);dp[i+t+1][j+1] = max(dp[i+t+1][j+1], dp[i][j] + a[i+t+1]);}else {dp[i+t-1][j-1] = max(dp[i+t-1][j-1], dp[i][j] + a[i+t-1]);dp[i+t][j] = max(dp[i+t][j], dp[i][j] + a[i+t]);dp[i+t+1][j+1] = max(dp[i+t+1][j+1], dp[i][j] + a[i+t+1]);}}}printf("%d\n", --ans);}int main(void){read();work();return 0;}
0 0
- 【DP】 Codeforces Round #286 A - Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 C. Mr. Kitayuta, the Treasure Hunter dp
- [Codeforces Round #286 DIV1A (CF506A)] Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter——dp
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter+dp+优化
- Codeforces Round #286 (Div. 2) C Mr. Kitayuta, the Treasure Hunter ( DP )
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter(经典的DP)
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter dp+范围压缩
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter dp
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter (dp)
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(DP)
- CodeForces 506 Div.1 A. Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2) C题 Mr. Kitayuta, the Treasure Hunter (DFS+记忆化DP)
- cf286C Mr. Kitayuta, the Treasure Hunter dp
- dp Codeforces505C Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter
- IO学习笔记
- XML之DOM解析模型
- 设计模式学习
- 推荐系统
- CF 505A Mr. Kitayuta's Gift(暴力)
- 【DP】 Codeforces Round #286 A - Mr. Kitayuta, the Treasure Hunter
- 足球与oracle系列(6):伴随建库的亚洲杯——加油中国队
- 为什么浏览器User-agent总是有Mozilla字样——User-agent 里的历史故事
- NameValueCollection怎么用
- 30-40岁的程序员们,请把一些账算清楚,为过冬做准备(二)
- 20150119 hnyq
- iOS开发网络篇—数据缓存
- 测试编辑问题
- 【用户管理】查看用户登入信息