【DP】 Codeforces Round #286 A - Mr. Kitayuta, the Treasure Hunter
2015-01-19 08:48
393 查看
注意到步数的改变量最多为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;} // head int 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; }
相关文章推荐
- cf#186-C. Mr. Kitayuta, the Treasure Hunter-dp(预推断+offset)
- Codeforces 505C Mr. Kitayuta, the Treasure Hunter DP+技巧优化
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter——dp
- CF 505C(Mr. Kitayuta, the Treasure Hunter-Dp考虑可用范围)
- CF - 286 - div2 - C - Mr. Kitayuta, the Treasure Hunter (DP)
- 【CodeForces506A】【DP】【记忆化搜索】Mr. Kitayuta, the Treasure Hunter 题解
- CF 286DIV2 C. Mr. Kitayuta, the Treasure Hunter(dp)
- CF505C——Mr. Kitayuta, the Treasure Hunter(DP)
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)
- dp cf C. Mr. Kitayuta, the Treasure Hunter
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter (dp)
- Codeforces Round #286 Div.1 A 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 (DFS+记忆化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
- #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter
- Codeforces Round #286 (Div. 2)C. Mr. Kitayuta, the Treasure Hunter
- Mr. Kitayuta, the Treasure Hunter