HDU_3182_Hamburger Magi_状态压缩dp
Hamburger Magi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 509 Accepted Submission(s): 163
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!
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.
4 90
243 464 307 298
79 58 0 72
3 2 3 4
2 1 4
1 1
0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; struct Node
{
int value;
int cost;
int cnt;
int rela[];
} ham[]; struct Node1
{
int value;
int cost;
};
Node1 dp[<<];
int main()
{
int t,kind,ener;
scanf("%d",&t);
while(t--)
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&kind,&ener);
for(int i=; i<=kind; i++)
scanf("%d",&ham[i].value);
for(int i=; i<=kind; i++)
scanf("%d",&ham[i].cost);
for(int i=; i<=kind; i++)
{
scanf("%d",&ham[i].cnt);
for(int j=; j<ham[i].cnt; j++)
scanf("%d",&ham[i].rela[j]);
}
int en=<<kind;
int ans=;
dp[].cost=dp[].value=;
for(int j=; j<en; j++)
{
if(dp[j].value==-)
continue;
for(int i=; i<=kind; i++)
{
int tem=<<(kind-i);
if(j&tem)
continue;
int flag=;
for(int k=; k<ham[i].cnt; k++)
{
int temp=<<(kind-ham[i].rela[k]);
if(!(temp&j))
{
flag=;
break;
}
}
if(flag)
{
dp[j+tem].value=dp[j].value+ham[i].value;
dp[j+tem].cost=dp[j].cost+ham[i].cost;
}
}
}
for(int i=; i<en; i++)
{
if(dp[i].cost>ener)
continue;
if(ans<dp[i].value)
ans=dp[i].value;
}
printf("%d\n",ans);
}
return ;
}
HDU_3182_Hamburger Magi_状态压缩dp的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- cocos2d-x 3.6版连连看版本号控制
为了以后的开发和管理.源代码开发必须要使用版本号控制.我们当然选择git来做版本号控制了. 假设你在终端输入git,提示不是一个命令的话.那就说明你的机器没有安装git工具.那就安装一个,百度之有非常 ...
- HDU 1226 超级password
跟POJ 1465 multiple 类是.仅仅只是多了2个条件,长度不能超过500.还有就是 可能不是十进制. bfs+同余定理,就是用 mod 来判重. G++ 15ms 每次枚举一位,然后记录下 ...
- Creo二次开发—内存处理
#include <ProDisplist.h> ProError ProDisplistInvalidate(ProMdl model) Invalidates the two- or ...
- 操作JSON对象
JSON类型对象,最简单了,就是键值对,key:value.key:value.一直不停地key:value下去,层层嵌套,理论上多少层都可以,只要你喜欢. 可是,每次应用JSON,我都心烦意乱,甚至 ...
- 美国诚实签经验——IMG全球医疗险,TODO
那么,诚实签最关键的4个要点 是什么呢? 第一,证明你有一定的经济实力. 可能需要房产.存款等证明,也需要银行信用卡或借记卡半年流水证明(让人信服的每月进帐和消费能力). 这些是为了证明,你可以支付在 ...
- obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
接下来我就简单跟大家介绍一下利用nginx来搭建流媒体服务器. 我选择的是腾讯云服务器 1.下载nginx-rtmp-module: nginx-rtmp-module的官方github地址:http ...
- IJ:Eclipse快捷键大全
ylbtech-IJ:Eclipse快捷键大全 1.返回顶部 1. Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加 ...
- bat 截取字符串(for命令) 推荐收藏
摘自:http://www.jb51.net/article/50354.htm 今天需要用批处理命令处理文件夹中的文件,需要用到bat中的for命令以及字符串截取的一些命令.在上面的链接中找到许多有 ...
- ViewModel、ViewData、ViewBag、TempData、Session之间的区别和各自的使用方法
ViewModel ViewModel 是一个用来渲染 ASP.NET MVC 视图的强类型类,可用来传递来自一个或多个视图模型(即类)或数据表的数据.可将其看做一座连接着模型.数据和视图的桥梁 ...
- P3953 逛公园(dp,最短路)
P3953 逛公园 题目描述 策策同学特别喜欢逛公园.公园可以看成一张NN个点MM条边构成的有向图,且没有 自环和重边.其中1号点是公园的入口,NN号点是公园的出口,每条边有一个非负权值, 代表策策经 ...