1 #include "bits/stdc++.h" 2 using namespace std; 3 int T; 4 5 int dp[40000]; 6 int totene[40000]; 7 8 int N, E; 9 int val[20], ene[20], cond[20]; 10 11 const int INF = 0x3f3f3f3f; 12 13 int main() 14 { 15 scanf("%d", &T); 16 while(T--) { 17 memset(cond, 0, sizeof(cond)); 18 memset(dp, 0xf3, sizeof(dp)); 19 dp[0] = 0; 20 scanf("%d%d", &N, &E); 21 int res = 0; 22 int i; 23 for(i = 1; i <= N; ++i) { 24 scanf("%d", &val[i]); 25 } 26 for(i = 1; i <= N; ++i) { 27 scanf("%d", &ene[i]); 28 } 29 int M, item; 30 for(i = 1; i <= N; ++i) { 31 scanf("%d", &M); 32 while(M--) { 33 scanf("%d", &item); 34 cond[i] |= (1 << (item - 1)); 35 } 36 } 37 int tot_s = (1 << N) - 1; 38 int s, step_s, pre_s; 39 for(s = 1; s <= tot_s; ++s) { 40 for(item = 1; item <= N; ++item) { 41 42 step_s = (1 << (item - 1)); 43 pre_s = s ^ step_s; 44 if(dp[pre_s] < 0) { 45 continue; 46 } 47 48 if((step_s & s) && ((pre_s & cond[item]) == cond[item])) { 49 // if(dp[s] == INF) { 50 totene[s] = totene[pre_s] + ene[item]; 51 // } 52 dp[s] = max(dp[s], dp[pre_s] + val[item]); 53 if(totene[s] <= E) { 54 res = max(res, dp[s]); 55 } 56 break; 57 } 58 } 59 } 60 printf("%d\n", res); 61 } 62 } 63 64 65 //4 66 //4 4 67 //1 1 1 1 68 //1 1 1 1 69 //0 70 //1 1 71 //2 1 2 72 //3 1 2 3 73 74 //4 75 //4 4 76 //1 1 1 1 77 //1 1 1 1 78 //1 2 79 //1 1 80 //2 1 2 81 //3 1 2 3