HDU 3182 - Hamburger Magi - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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!
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.
total value HamMagi can get.
#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]的更多相关文章
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu_3182_Hamburger Magi(状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前 ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
- HDU 3362 Fix (状压DP)
题意:题目给出n(n <= 18)个点的二维坐标,并说明某些点是被固定了的,其余则没固定,要求添加一些边,使得还没被固定的点变成固定的, 要求总长度最短. 析:由于这个 n 最大才是18,比较小 ...
随机推荐
- iOS中js与objective-c的交互(转)
因为在iOS中没有WebKit.Framework这个库的,所以也就没有 windowScriptObject对象方法了.要是有这个的方法的话 就方便多了,(ps:MacOS中有貌似) 现在我们利用其 ...
- Matlab 随机数字
1.随机生成仅仅有0.1元素的矩阵(m行n列) A=round(rand(m,n)) 2.随机生成每行有若干个0,1元素的矩阵,比方每行仅仅有2个元素为1,其它元素为0 A=zeros(4,5) fo ...
- Shiro集成Spring
本篇博客主要讲述的是两者的集成.不涉及到各自的详细细节和功能. 因为官方给出的文档不够具体,对新手而言通过官方文档还不可以非常快的搭建出SpringShiro的webproject.本博客将通过实际的 ...
- centos7 python3.5中引入sqlite3
在centos系统中创建Django app,报错如下: django.core.exceptions.ImproperlyConfigured: Error loading either pysql ...
- bodgeit测试平台
下载war安装包:https://code.google.com/archive/p/bodgeit/downloads http://resources.infosecinstitute.com/t ...
- SimpleDateFormat 取当前周的周一和周日的日期,当前月第一个和最后一天的日期
/** * 类说明 :以及获取当前周的周一和周日的日期,当前月第一个和最后一天的日期 * 日期格式化:格式参数 G 年代标志符 y 年 M 月 d 日 h 时 在上午或下午 (1~12) ...
- 基于VLAN的二三层转发
[章节内容]1 MAC地址2 冲突域和广播域3 集线器.交换机.路由器 3.1 集线器 3.2 网桥和交换机 3.3 路由器4 VLAN 4.1 VLAN帧格式 4.1.1 ...
- WEB中会话跟踪[转]
今天晚上去华工参加睿智融科的笔试,问到web会话跟踪,一脸懵比,这个词听都没听过,回来后百度下,发现其实会话跟踪的内容我基本都了解的~_~ 转自:http://www.cnblogs.com/gaop ...
- 大智慧F10离线资料压缩包带F10关键字过滤软件--更新于2014-01-06.rar 184MB
大智慧F10离线资料包带F10关键字过滤软件--更新于2014-01-06.rar 移步到百度网盘下载: http://pan.baidu.com/s/1c01PDnE
- KMP算法的实现(Java语言描述)
标签:it KMP算法是模式匹配专用算法. 它是在已知模式串的next或nextval数组的基础上执行的.如果不知道它们二者之一,就没法使用KMP算法,因此我们需要计算它们. KMP算法由两部分组成: ...