【每日一题】Mr. Kitayuta, the Treasure Hunter
Mr. Kitayuta, the Treasure Hunter
https://ac.nowcoder.com/acm/problem/110793
题意:
思路:
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N = 3e4 +10; const int inf = 0x3f3f3f3f; int a[N],n,d,f[N][510]; int base = 250; int main(){ scanf("%d%d",&n,&d); for(int i = 0,x;i < n;i++){ scanf("%d",&x); a[x]++; } memset(f,-inf,sizeof(f)); f[d][base] = a[d]; int ans = f[d][base]; for(int i = d;i <= 30000;i++){ for(int j = 0;j <= 500;j++){ int last = i - (d + j - base); if(last < d || last >= i) continue; for(int k = -1;k <= 1;k++){ if(j + k >= 0) f[i][j] = max(f[i][j],f[last][j + k] +a[i]); } ans = max(ans,f[i][j]); } } printf("%d\n",ans); return 0; }
每日一题 文章被收录于专栏
每题一题题目