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,比较小 ...
随机推荐
- android:versionCode和android:versionName 用途(转)
转自:http://blog.csdn.net/wh_19910525/article/details/8660416 Android的版本可以在androidmainfest.xml中定义,主要有a ...
- 【转载】springboot + swagger
注:本文参考自 http://www.jianshu.com/p/0465a2b837d2 https://www.cnblogs.com/java-zhao/p/5348113.html swagg ...
- 九度 1464:Hello World for U
题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape ...
- C#索引器理解
C#索引器介绍举例 索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 ( ...
- Libjingle库 综述
国内现在很多语音聊天工具都是基于TURN方式实现的,包括YY.AK等等,这种方式对于服务器的性能要求很高,而且在用户量增大的时候,服务器压力也会越来越大,用户的语音质量也会受到很大影响.而基于P2P方 ...
- 深度缓存ZBuffer线性化
double linearizeDepth(double nearz,double farz,double depth) { depth = 2.0 * depth - 1.0; return (2. ...
- Android文件系统编译出错记录
错误1: 注意:external/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java 使用了未经检查或不 ...
- C++ template —— trait与policy类(七)
第15章 trait与policy类---------------------------------------------------------------------------------- ...
- Delphi应用程序的调试(五)其他调试工具
Delphi应用程序的调试(五)其他调试工具 Delphi7中提供了一些附加调试工具来帮助用户检查程序错误.从性能上讲,其中一些工具属于高级调试工具.尽管高级调试工具不像其他工具那样常用,但对于经验丰 ...
- 剑指offer——35复杂链表的复制
这题很是巧妙. 突破了常规思维. 竟然可以把传入进来的链表和复制的链表链在一起.然后再算出slibling指针.最后在分离. 直接把空间复杂度变为O(1)了. 很巧妙,很实用. 题目: 请实现函数Co ...