标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 509 Accepted Submission(s): 163
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct Node { int value; int cost; int cnt; int rela[20]; } ham[20]; struct Node1 { int value; int cost; }; Node1 dp[1<<15]; int main() { int t,kind,ener; scanf("%d",&t); while(t--) { memset(dp,-1,sizeof(dp)); scanf("%d%d",&kind,&ener); for(int i=1; i<=kind; i++) scanf("%d",&ham[i].value); for(int i=1; i<=kind; i++) scanf("%d",&ham[i].cost); for(int i=1; i<=kind; i++) { scanf("%d",&ham[i].cnt); for(int j=0; j<ham[i].cnt; j++) scanf("%d",&ham[i].rela[j]); } int en=1<<kind; int ans=0; dp[0].cost=dp[0].value=0; for(int j=0; j<en; j++) { if(dp[j].value==-1) continue; for(int i=1; i<=kind; i++) { int tem=1<<(kind-i); if(j&tem) continue; int flag=1; for(int k=0; k<ham[i].cnt; k++) { int temp=1<<(kind-ham[i].rela[k]); if(!(temp&j)) { flag=0; break; } } if(flag) { dp[j+tem].value=dp[j].value+ham[i].value; dp[j+tem].cost=dp[j].cost+ham[i].cost; } } } for(int i=0; i<en; i++) { if(dp[i].cost>ener) continue; if(ans<dp[i].value) ans=dp[i].value; } printf("%d\n",ans); } return 0; }
HDU_3182_Hamburger Magi_状态压缩dp
标签:
原文地址:http://www.cnblogs.com/jasonlixuetao/p/5490197.html