bzoj 1270 [BeijingWc2008]雷涛的小猫

sb dp 没啥好说的。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> >

using namespace std;

const int N = 2000 + 7;
const int M = 10 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int zero = 160;

int n, h, d, dp[N][N], mx[N], a[N][N];
int main() {
    scanf("%d%d%d", &n, &h, &d);
    for(int i = 1; i <= n; i++) {
        int m; scanf("%d", &m);
        for(int j = 1; j <= m; j++) {
            int pos; scanf("%d", &pos);
            a[i][pos]++;
        }
    }

    for(int j = h; j >= 0; j--) {
        for(int i = 1; i <= n; i++) {
            dp[i][j] = dp[i][j + 1] + a[i][j];
            if(j + d <= h) dp[i][j] = max(dp[i][j], mx[j + d] + a[i][j]);
            mx[j] = max(mx[j], dp[i][j]);
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max(ans, dp[i][0]);

    printf("%d
", ans);
    return 0;
}
/*
*/
原文地址:https://www.cnblogs.com/CJLHY/p/9119738.html