传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1270
noip级水题……
f[i][j]表示第i棵树,在j高度能获得的最大值
Code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2004;
int a[maxn][maxn];
int f[maxn][maxn];
int mx[maxn];
int n,h,dt;
int main(){
scanf("%d%d%d",&n,&h,&dt);
for(int i=1;i<=n;i++){
int nn;scanf("%d",&nn);
for(int j=1;j<=nn;j++){
int x;scanf("%d",&x);
a[i][x]++;
}
}
for(int j=h;j>=0;j--)
for(int i=1;i<=n;i++){
f[i][j]=max(f[i][j],f[i][j+1]);
if(j+dt<=h)f[i][j]=max(f[i][j],mx[j+dt]);
f[i][j]+=a[i][j];
mx[j]=max(mx[j],f[i][j]);
}cout<<mx[0]<<endl;
return 0;
}