1#include"bits/stdc++.h"2 using namespacestd;3 intT;4 5 intdp[40000];6 inttotene[40000];7 8 intN, E;9 intval[ -], ene[ -], cond[ -];Ten One Const intINF =0x3f3f3f3f; A - intMain () - { thescanf"%d", &T); - while(t--) { -memset (COND,0,sizeof(cond)); -Memset (DP,0xf3,sizeof(DP)); +dp[0] =0; -scanf"%d%d", &n, &E); + intres =0; A inti; at for(i =1; I <= N; ++i) { -scanf"%d", &val[i]); - } - for(i =1; I <= N; ++i) { -scanf"%d", &ene[i]); - } in intM, item; - for(i =1; I <= N; ++i) { toscanf"%d", &M); + while(m--) { -scanf"%d", &item); theCond[i] |= (1<< (Item-1)); * } $ }Panax Notoginseng inttot_s = (1<< N)-1; - ints, step_s, pre_s; the for(s =1; s <= tot_s; ++s) { + for(item =1; Item <= N; ++Item) { A thestep_s = (1<< (Item-1)); +pre_s = s ^step_s; - if(Dp[pre_s] <0) { $ Continue; $ } - - if((step_s & S) && ((pre_s & cond[item]) = =Cond[item])) { the //if (dp[s] = = INF) { -Totene[s] = totene[pre_s] +Ene[item];Wuyi // } theDp[s] = max (Dp[s], dp[pre_s] +Val[item]); - if(Totene[s] <=E) { Wures =Max (res, dp[s]); - } About Break; $ } - } - } -printf"%d\n", res); A } + } the - $ //4 the //4 4 the //1 1 1 1 the //1 1 1 1 the //0 - //1 1 in //2 1 2 the //3 1 2 3 the About //4 the //4 4 the //1 1 1 1 the //1 1 1 1 + //1 2 - //1 1 the //2 1 2Bayi //3 1 2 3
HDU 3182-Shape pressure DP