#include<bits/stdc++.h>
using namespace std;
int n,T,m,x,y,f[2][1100];
int main() {
scanf("%d",&T);
for(int kase=1; kase<=T; kase++) {
memset(f,-1,sizeof f),f[0][0]=0;
scanf("%d%d",&n,&m);
for(int i=1,cur=1; i<=n; i++,cur^=1) {
scanf("%d%d",&x,&y);
int k=0;
for(int j=1,t; j<=y; j++)scanf("%d",&t),k|=1<<(t-1);
for(int j=0; j<1<<m; j++) {
f[cur][j]=max(f[cur][j],f[!cur][j]);
if(~f[!cur][j]) {
f[cur][j^k]=max(f[cur][j^k],f[!cur][j]+x);
}
}
}
printf("%d\n",f[n&1][(1<<m)-1]);
}
}
原文:https://www.cnblogs.com/chasedeath/p/11269391.html