题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182
题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前汉堡需要先做出列出的汉堡,求最大的价值
题解:状压DP
#include<cstdio>
#define FFC(i,a,b) for(int i=a;i<=b;++i)
int T,n,all,end,now,cur,ans,flag,v[16],e[16],a[16][16],dp[1<<16],c[1<<16];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&all),end=(1<<n)-1,c[0]=all;
FFC(i,1,n)scanf("%d",&v[i]);FFC(i,1,n)scanf("%d",&e[i]);
FFC(i,1,n){
scanf("%d",&a[i][0]);
FFC(j,1,a[i][0])scanf("%d",&a[i][j]);
}
FFC(i,0,end)dp[i]=-1;
dp[0]=0,ans=0;
FFC(i,0,end){
if(dp[i]==-1)continue;
FFC(j,0,n-1){
now=1<<j,flag=0,cur=now|i;
if((i&now)==0&&c[i]>=e[j+1]){
FFC(k,1,a[j+1][0])if(((1<<(a[j+1][k]-1))&i)==0){flag=1;break;}
if(flag)continue;
if(dp[cur]<dp[i]+v[j+1])
dp[cur]=dp[i]+v[j+1],c[cur]=c[i]-e[j+1],ans=ans>dp[cur]?ans:dp[cur];
}
}
}
printf("%d\n",ans);
}
return 0;
}