题目链接: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. 上机题目(0基础)- 用数组实现记事本(Java)

    用java实现一个记事本程序,记录记下的按键,代码例如以下: package com.java.test; import java.awt.Graphics; import java.awt.even ...

  2. Go之单元测试

    go单元测试需要按照gotest的规范来编写: 1.文件名必须以xx_test.go命名 2.方法必须是Test[^a-z]开头 3.方法参数必须 t *testing.T   在运行gotest的时 ...

  3. Splash scroll_position 属性

    scroll_position属性用于控制页面上下或左右滚动,如下,表示控制页面向下滚动 400 像素值并返回结果图, function main(splash, args) assert(splas ...

  4. PPT高手必须树立的十个理念

    08 2014年08月 [263职场技巧]PPT高手必须树立的十个理念 理念一:文字是用来瞟的,不是读的 我们时不时听到这样的言论:“PPT很简单,就是把Word里的文字复制.粘贴呗.”这其实是对PP ...

  5. vue再次入手(数据传递②)

    接上篇~ 5.最后一种,互通:无所谓父组件或者是子组件,而是随时随地都能调用到数据的一种方法.便是利用vuex来管理数据,官网描述: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它 ...

  6. tts文本转语音服务

    1. 谷歌tts http://translate.google.cn/translate_tts?ie=UTF-8&tl=zh-CN&q=谷歌 2. 百度tts http://tts ...

  7. Mac 下如何下载、启动和关闭Tomcat 和管理Mac自带的Apache

     Mac 下载.启动和关闭Tomcat 1. 下载Tomcat(地址:tomcat.apache.org),选择适合的版本(这里选择6.0.48),点击“Download”,之后在新页面点击“Core ...

  8. KMP算法的实现(Java语言描述)

    标签:it KMP算法是模式匹配专用算法. 它是在已知模式串的next或nextval数组的基础上执行的.如果不知道它们二者之一,就没法使用KMP算法,因此我们需要计算它们. KMP算法由两部分组成: ...

  9. C++ sort函数用法 C中的qsort

    需要包含#include <algorithm>MSDN中的定义: template<class RanIt>     void sort(RanIt first, RanIt ...

  10. PCL—低层次视觉—关键点检测(iss&Trajkovic)

    关键点检测往往需要和特征提取联合在一起,关键点检测的一个重要性质就是旋转不变性,也就是说,物体旋转后还能够检测出对应的关键点.不过说实话我觉的这个要求对机器人视觉来说是比较鸡肋的.因为机器人采集到的三 ...