题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description
In the mysterious forest, there is a group of Magi. Most of them like to eat human beings, so they are called “The Ogre Magi”, but there is an special one whose favorite food is hamburger, having been jeered by the others as “The Hamburger Magi”.
Let’s give The Hamburger Magi a nickname
“HamMagi”, HamMagi don’t only love to eat but also to make hamburgers, he makes
N hamburgers, and he gives these each hamburger a value as Vi, and each will
cost him Ei energy, (He can use in total M energy each day). In addition, some
hamburgers can’t be made directly, for example, HamMagi can make a “Big Mac”
only if “New Orleams roasted burger combo” and “Mexican twister combo” are all
already made. Of course, he will only make each kind of hamburger once within a
single day. Now he wants to know the maximal total value he can get after the
whole day’s hard work, but he is too tired so this is your task now!
 
Input
The first line consists of an integer C(C<=50),
indicating the number of test cases.
The first line of each case consists of
two integers N,E(1<=N<=15,0<=E<=100) , indicating there are N kinds
of hamburgers can be made and the initial energy he has.
The second line of
each case contains N integers V1,V2…VN, (Vi<=1000)indicating the value of
each kind of hamburger.
The third line of each case contains N integers
E1,E2…EN, (Ei<=100)indicating the energy each kind of hamburger cost.
Then
N lines follow, each line starts with an integer Qi, then Qi integers follow,
indicating the hamburgers that making ith hamburger needs.
 
Output
For each line, output an integer indicating the maximum
total value HamMagi can get.
 
Sample Input
1
4 90
243 464 307 298
79 58 0 72
3 2 3 4
2 1 4
1 1
0
 
Sample Output
298
 
题意:
给出N个汉堡包,编号1~N,做汉堡包的法师共有能量E;
每个汉堡包给出价值和需要消耗的能量,以及做这个汉堡包需要的前置汉堡包k1,k2, … , ki;
求在最多消耗能量E的情况下,做出来的汉堡最大价值和;
 
题解:
状态i表示哪些汉堡包做了,哪些汉堡包还没做;
dp[i].val:当前情况下,最大价值和;
dp[i].ene:当前情况下,消耗了多少能量;
 
AC代码:
 #include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int N,E;
struct Ham{
int val,ene,pre;
}ham[];
struct DP{
int val,ene;
}dp[<<];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&N,&E);
for(int i=;i<=N;i++) scanf("%d",&ham[i].val);
for(int i=;i<=N;i++) scanf("%d",&ham[i].ene);
for(int i=,q;i<=N;i++)
{
scanf("%d",&q);
ham[i].pre=;
for(int j=,tmp;j<=q;j++)
{
scanf("%d",&tmp);
ham[i].pre|=<<(tmp-);
}
} int ed_state=(<<N)-,ans=;
dp[].val=, dp[].ene=;
for(int state=;state<=ed_state;state++)
{
if(dp[state].val==-) continue;
for(int i=;i<=N;i++)
{
if( state&(<<(i-)) || (state&ham[i].pre) != ham[i].pre || dp[state].ene+ham[i].ene > E ) continue;
int next_state=state|(<<(i-));
if(dp[state].val+ham[i].val > dp[next_state].val)
{
dp[next_state].val=dp[state].val+ham[i].val;
dp[next_state].ene=dp[state].ene+ham[i].ene;
if(dp[next_state].ene<=E) ans=max(dp[next_state].val,ans);
}
}
} printf("%d\n",ans);
}
}

HDU 3182 - Hamburger Magi - [状压DP]的更多相关文章

  1. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  2. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. hdu_3182_Hamburger Magi(状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前 ...

  4. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  5. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  6. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

  7. hdu 4856 Tunnels (bfs + 状压dp)

    题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...

  8. HDU 4272 LianLianKan (状压DP+DFS)题解

    思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...

  9. HDU 3362 Fix (状压DP)

    题意:题目给出n(n <= 18)个点的二维坐标,并说明某些点是被固定了的,其余则没固定,要求添加一些边,使得还没被固定的点变成固定的, 要求总长度最短. 析:由于这个 n 最大才是18,比较小 ...

随机推荐

  1. Centos6.3 下使用 Tomcat-6.0.43 非root用户 部署 生产环境 端口转发方式

    一.安装JDK环境 方法一. 官方下载链接 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260 ...

  2. Ubuntu 12.04下安装QQ 2012 Beta3(转)

    Ubuntu 12.04下安装QQ 2012 Beta3   由于wine的发展非常迅速.现在网上的利用老版本的wine来安装QQ2012的教程已经有些过时了.实际上操作起来非常简单: 第一步:Ctr ...

  3. ios开发之--[_NSInlineData objectForKeyedSubscript:]

    reason: '-[_NSInlineData objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fa2049 ...

  4. centos 上不了网了

    昨天还用的好好的,今天就上不了网了,郁闷,不过,正好是一次学习linux网络配置的好机会,这会已经把它折腾好了,此文就是在linux下面的浏览器中写的! 先检查一下虚拟机中的网络设置是否正常,由于我的 ...

  5. 绑定方式开始服务&调用服务的方法

    1.编写activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  6. Splash 简介与安装

    Splash 说白了就是一个轻量级的浏览器,利用它,我们同样可以实现跟其他浏览器一样的操作,我们使用 Docker 来安装 Splash: [root@localhost ~]# docker run ...

  7. Steam安装Google Earth VR

    打开Steam 打开火狐浏览器 输入steam://install/348250

  8. 手机端点击复制链接到剪切板(以及PC端)

    一直在找如何能点击按钮将一串字符串放到手机的剪切板上,但是可能是因为搜索的关键字不对,一直无果. 向同事请教了一下,给了一个clickboard.js的插件.开始试验的时候,使用手机自带浏览器进行测试 ...

  9. Bootstrap - select2

    1.调整select2下拉框的宽度 <style> .select2-container .select2-choice { height: 28px; line-height: 28px ...

  10. linux进程永久放后台运行

    我们使用ssh连接服务器之后,如果在执行某个命令需要时间特别长,当把终端断掉之后,命令就自动停止了一般我们在ssh客户端执行命令之后,默认他的父进程是ssh,所以把ssh终端关掉之后,子进程也就被自动 ...