题目链接: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. Linux查看系统进程

    1. 在 LINUX 命令平台输入 1-2 个字符后按 Tab 键会自动补全后面的部分(前提是要有这个东西,例如在装了 tomcat 的前提下, 输入 tomcat 的 to 按 tab).2. ps ...

  2. c# windows服务

    参考:https://www.cnblogs.com/knowledgesea/p/3616127.html 序言 前段时间做一个数据迁移项目,刚开始用B/S架构做的项目,但B/S要寄存在IIs中,而 ...

  3. Go之并发处理(售票问题)

    老问题:模拟一个售票窗口进行售票 先定义类型Ticket(车票)和Conductor(销售员)--偷懒了,把售票和产票都交给Conductor了 package util import () //-- ...

  4. grid布局合并单元格

    参考:http://www.w3cplus.com/css3/css-grid-layout-merge-cells.html <!DOCTYPE html> <html lang= ...

  5. mysql操作类

    同事今天推荐了一个mysql链接操作的类,地址 https://github.com/joshcam/PHP-MySQLi-Database-Class  大概看了一下,还是不错的,有点意思,先记录一 ...

  6. Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x

    Mybatis整合通用Dao,Mybatis整合通用Mapper,MyBatis3.x整合通用 Mapper3.5.x ============================== 蕃薯耀 2018年 ...

  7. 如何查看MySQL的当前存储引擎?

    如何查看MySQL的当前存储引擎? 一般情况下,mysql会默认提供多种存储引擎,你可以通过下面的查看:   看你的mysql现在已提供什么存储引擎: mysql> show engines; ...

  8. NFS exportfs 命令

    exportfs 是在服务端上使用的命令,主要用来操作挂载的目录,比如我们修改了NFS配置文件,需要重启NFS服务,如果客户端正在读写,那么重启NFS服务对客户端是有影响的,因此 exportfs 命 ...

  9. 为啥RESTFULL如此重要?

    为啥RESTFULL如此重要? 2014-6-3 20:13| 发布者: admin| 查看: 57| 评论: 0|来自: java365 摘要: 本文我们将讨论REST,它定义了一组体系架构原则,您 ...

  10. code_blocks 使用操作手册

                                                                              38 39 编译以上程序,产生如下提示信息. 如此简 ...