Hamburger Magi(hdu 3182)
Hamburger Magi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 437 Accepted Submission(s): 144
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.
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<stack>
8 using namespace std;
9 typedef struct qq
10 {
11 int x;//记入当前状态最大价值
12 int y;//记录剩余的体力
13 } mm;
14 typedef struct pp
15 {
16 int x;
17 int y;
18 int cnt;
19 int a[20];
20 } ss;//记入面包的价值消耗以及要求
21 ss kk[22];
22 mm dp[1<<16];
23 int main(void)
24 {
25 int n,i,j,k,p,q;
26 scanf("%d",&k);
27 while(k--)
28 {
29 scanf("%d %d",&p,&q);
30 for(i=0; i<p; i++)
31 {
32 scanf("%d",&kk[i].x);
33 }
34 for(i=0; i<p; i++)
35 {
36 scanf("%d",&kk[i].y);
37 }
38 for(i=0; i<p; i++)
39 {
40 scanf("%d",&kk[i].cnt);
41 for(j=0; j<kk[i].cnt; j++)
42 {
43 scanf("%d",&kk[i].a[j]);
44 kk[i].a[j]-=1;
45 }
46 }
47 for(i=0; i<(1<<16); i++)
48 {
49 dp[i].x=0;
50 dp[i].y=-100;
51 }
52 int maxx=0;
53 dp[0].y=q;//初始化
54 for(i=1; i<(1<<p); i++)
55 {
56 for(j=0; j<p; j++)
57 {
58 if(i&(1<<j))//判断是否在当前的状态下
59 {
60 int c=i^(1<<j);//找这个状态的前一个状态
61 int s=0;
62 for(s=0; s<kk[j].cnt; s++)//判断要求是否成立也就是前一个状态下是否有做这个面包的要求
63 {
64 if((c&(1<<(kk[j].a[s])))==0)
65 {
66 break;
67 }
68 }
69 if(s==kk[j].cnt)
70 {
71 if(dp[c].y>=kk[j].y)
72 {
73 int cc=dp[c].x+kk[j].x;
74 if(cc>dp[i].x)
75 {
76 dp[i].x=cc;
77 dp[i].y=dp[c].y-kk[j].y;
78 }
79 if(dp[i].x>maxx)
80 {
81 maxx=dp[i].x;//更新最大值
82 }
83 }
84 }
85 }
86
87 }
88
89 }
90 printf("%d\n",maxx);
91 }
92 return 0;
93 }
状压DP
Hamburger Magi(hdu 3182)的更多相关文章
- HDU 3182 - Hamburger Magi - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 3182 Hamburger Magi(状压dp)
题目链接:pid=3182">http://acm.hdu.edu.cn/showproblem.php?pid=3182 Problem Description In the mys ...
- [状压dp]HDOJ3182 Hamburger Magi
题意 大致是: 有n个汉堡 m块钱 (n<=15) 然后分别给n个汉堡的能量 再分别给n个汉堡所需的花费 然后下面n行 第i行有x个汉堡要在i汉堡之前吃 然后给出这x个汉堡的编号 输出 能获得 ...
- 状态压缩 HDU 3182
t组数据 n个汉堡 e的能量 接下来的2行 val n个 得到的权 cost n个 花去的能量 接下来n行 每行一个q q个数字 代表这类汉堡做好要的前提 每个汉堡只能用一次 #inclu ...
- HDU 3182 ——A Magic Lamp(思维)
Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lam ...
- HDU_3182_Hamburger Magi_状态压缩dp
Hamburger Magi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ZOJ 3182 HDU 2842递推
ZOJ 3182 Nine Interlinks 题目大意:把一些带标号的环套到棍子上,标号为1的可以所以操作,标号i的根子在棍子上时,只有它标号比它小的换都不在棍子上,才能把标号为i+1的环,放在棍 ...
- HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
随机推荐
- windows系统 svn自动更新
如果对svn不熟悉,当svn上面有更新时,想看到实时效果,就得去web目录手动更新,比较麻烦 其它svn有一个自动更新的功能 利用 hook 在svn 仓库目录下面有一个hook目录 在post- ...
- 22 SHELL 获取当前路径
常见的一种误区,是使用 pwd 命令,该命令的作用是"print name of current/working directory",这才是此命令的真实含义,当前的工作目录,这里 ...
- linux 常用清空文件方法
1.vim 编辑器 vim /tmp/file :1,$d 或 :%d 2.cat 命令 cat /dev/null > /tmp/file
- my41_主从延迟大排查
半同步复制 主库执行 INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; SET GLOBAL rpl_semi_sync ...
- “==” 和 equals()的区别
※ "==" 和 equals()的区别 ※ == :比较. 基本数据类型比较的是值:. 引用类型比较的是地址值. ※ equals(Object o):1)不能比较基本数据类型, ...
- 什么是微服务,SpringBoot和SpringCloud的关系和区别
什么是微服务? 就目前而言对于微服务业界没有一个统一的,标准的定义.但通常而言,微服务是一种架构模式或者说是一种架构风格,它提倡单一应用程序划分为一组小的服务,每个服务在其独立的自己的进程中,服务之间 ...
- Springboot(1) helloworld 搭建环境
一 .springboot 运行环境: 1. jdk1.8:Spring Boot 推荐jdk1.7及以上:java version "1.8.0_112" 2.–maven3.x ...
- Jmeter——SMTP Sampler发送邮件
在平时测试过程中,也会出一些测试报告,那jmeter在不依托其他工具的情况下,可不可以发送邮件呢,自然是可以的. 我们直接使用SMTP Sampler即可. SMTP Sampler参数 我们来添加个 ...
- ES 6 新特性笔记
let 与 var 的区别 功能 let var 块级作用域 ️ 变量提升 ️ 重复声明(相同作用域内) ️ var 没有块级作用域的解决方法 使用函数替代块级作用域,以保证变量的正常使用,如: .. ...
- 日历的种类(Project)
<Project2016 企业项目管理实践>张会斌 董方好 编著 日历有三种:标准日历.24小时日历和夜班日历. 设置的位置在[项目]>[属性]>[更改工作时间]>[ ...