Code: Select all
#include <bits/stdc++.h>
using namespace std;
int t, h, f;
//vector<int> acorn[2010];
int acorn[2010][2010];
int dp[2010][2010];
bool vis[2010][2010];
int func(int, int);
int main() {
int c;
scanf("%d", &c);
while(c--) {
scanf("%d %d %d", &t, &h, &f);
memset(acorn, 0, sizeof acorn);
memset(vis, false, sizeof vis);
for(int i = 0; i < t; i++) {
int x;
scanf("%d", &x);
for(int j = 0; j < x; j++) {
int height;
scanf("%d", &height);
acorn[i][height]++;
}
}
int ans = -99999;
for(int i = 0; i < t; i++)
ans = max(ans, func(i, h));
printf("%d\n", ans);
}
int zero;
scanf("%d", &zero);
return 0;
}
int func(int tree, int height) {
if(height <= 0) {
return 0;
}
if(vis[tree][height]) return dp[tree][height];
int taken = -99999;
taken = max(taken, acorn[tree][height] + func(tree, height - 1));
for(int i = 0; i < t; i++) {
if(i == tree) continue;
if(height - f >= 0 && acorn[i][height - f])
taken = max(taken, acorn[tree][height] + func(i, height - f));
}
vis[tree][height] = true;
dp[tree][height] = taken;
return taken;
}