BJWC2008 雷涛的小猫

题目链接

题解

水DP
记录每一层的最大值用于优化转移。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
int f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar(); }
while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return f * x;
}
int n, h, d, dp[2005][2005] = {0}, maxi[2005] = {0}, cnt[2005][2005] = {0};
void init(){
n = read(), h = read(), d = read();
for(int i = 0; i < n; ++i){
int ni = read();
for(int j = 0; j < ni; ++j)
cnt[i][read()]++;
}
}
void solve(){
for(int i = 0; i < n; ++i)
dp[i][h] = cnt[i][h], maxi[h] = max(maxi[h], cnt[i][h]);
for(int i = h - 1; i >= 0; --i)
for(int j = 0; j < n; ++j){
dp[j][i] = dp[j][i + 1];
if(h - i >= d) dp[j][i] = max(dp[j][i], maxi[i + d]);
dp[j][i] += cnt[j][i];
maxi[i] = max(maxi[i], dp[j][i]);
}
printf("%d\n", maxi[0]);
}
int main(){
init();
solve();
return 0;
}