思路:多重背包;
#include <stdio.h>
#include <string.h>
int t,n,m;
int dp[1010],A[21][51],C[21][51],num[21];
int max(int x,int y)
{
return x > y?x:y;
}
int main()
{
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
memset(dp, 0,sizeof dp);
scanf("%d%d",&n,&m);
for (int i = 1;i <= n;i++)
{
scanf("%d",&num[i]);
for (int j = 0;j < num[i];j++)
scanf("%d%d",&A[i][j],&C[i][j]);
}
for (int i = 1;i <= n;i++)
{
for (int j = m;j >= 0;--j)
{
for (int k = 0;k < num[i];++k)
if (j >= A[i][k]) dp[j] = max(dp[j],dp[j - A[i][k]] + C[i][k]);
}
}
printf("%d\n",dp[m]);
}
return 0;
}