Simple DP:
DP (I,J) = Max (DP (x, y) +cnt[i][j], (x, y)-(I,J) is the legal path.
set F (i) = Max (DP (x, y)) (1≤x≤n, 1≤y≤i), g (i,j) = max (DP (i, K)) (1≤k≤j)
Then DP (I,J) = Max (f (J+delta), G (i,j+1)) +cnt[i][j]. Recursion can be. Time complexity O (NH)
-----------------------------------------------------------------------
#include <bits/stdc++.h>using namespace std;const int MAXN =; int N, H, Delta, CNT[MAXN][MAXN];int DP[MAXN][MAXN], F[MAXN], G[MAXN][MAXN];void init () {scanf ("%d%d%d", &n, &h, &delta);memset (CNT, 0, sizeof CNT);for (int i = 0; i < N; i++) {int t; scanf ("%d", &t);While (t--) {int h; scanf ("%d", &h);cnt[i][h]++;}}} void Work () {F[h] = 0;for (int i = 0; i < N; i++)F[h] = max (F[h], dp[i][h] = g[i][h] = cnt[i][h]);for (int h = h;--h;) {F[h] = f[h + 1];for (int i = 0; i < N; i++) {int t = g[i][h + 1];g[i][h] = t;if (H + delta <= h) t = max (T, f[h + delta));Dp[i][h] = t + cnt[i][h];F[h] = max (F[h], dp[i][h]);G[i][h] = max (G[i][h], dp[i][h]); }}int ans = 0;for (int i = 0; i < N; i++)ans = max (ans, dp[i][1]);printf ("%d\n", ans);}int main () {init ();Work ();return 0;}
-----------------------------------------------------------------------
1270: [BeijingWc2008] Leitao kitten time limit: Sec Memory Limit: 162 MB
Submit: 1004 Solved: 483
[Submit] [Status] [Discuss] Description Inputoutputsample InputSample Output8HINT
Source
Bzoj 1270: [BeijingWc2008] Leitao Kitten (DP)