Hamburger Magi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 437    Accepted Submission(s): 144

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块面包,给出他的价值以及所需消耗体力。
给出人物的体力,然后每个面包做需要一定的条件,就是在这个面包做前其他几个面包要做好。
问最后得到的价值最大。
思路:状压dp;
总共pow(2,n)的状态。
dp[i]表示在状态i所得到的价值的最大。
 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)的更多相关文章

  1. HDU 3182 - Hamburger Magi - [状压DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  2. HDU 3182 Hamburger Magi(状压dp)

    题目链接:pid=3182">http://acm.hdu.edu.cn/showproblem.php?pid=3182 Problem Description In the mys ...

  3. [状压dp]HDOJ3182 Hamburger Magi

    题意 大致是: 有n个汉堡 m块钱  (n<=15) 然后分别给n个汉堡的能量 再分别给n个汉堡所需的花费 然后下面n行 第i行有x个汉堡要在i汉堡之前吃 然后给出这x个汉堡的编号 输出 能获得 ...

  4. 状态压缩 HDU 3182

    t组数据 n个汉堡 e的能量 接下来的2行 val    n个 得到的权 cost  n个 花去的能量 接下来n行 每行一个q  q个数字 代表这类汉堡做好要的前提  每个汉堡只能用一次 #inclu ...

  5. HDU 3182 ——A Magic Lamp(思维)

    Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lam ...

  6. HDU_3182_Hamburger Magi_状态压缩dp

    Hamburger Magi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. ZOJ 3182 HDU 2842递推

    ZOJ 3182 Nine Interlinks 题目大意:把一些带标号的环套到棍子上,标号为1的可以所以操作,标号i的根子在棍子上时,只有它标号比它小的换都不在棍子上,才能把标号为i+1的环,放在棍 ...

  8. HDU 3853:LOOPS(概率DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description   Akemi Homura is a M ...

  9. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

随机推荐

  1. 学习 DDD - 通用语言的模式

    大家好,我是霸戈,这周学习了一些关于领域驱动设计的知识 ,对比较深刻的地方做了不少笔记,分享给大家. 在日常需求讨论的时候,经常会碰到一个需求会议开了一个多小时还没有达成共识.作为业务方(领域专家)明 ...

  2. day08 Nginx模块

    day08 Nginx模块 lnmp架构 l :Linux n :Nginx m :MySQL p :Python/PHP lnmp架构:是最简单的架构 Nginx中的模块(Python模块):前提是 ...

  3. day11 系统安全

    day11 系统安全 复习总结 文件 1.创建 格式:touch [路径] [root@localhost ~]# touch 1.txt # 当前路径创建 [root@localhost ~]# t ...

  4. C语言内自定义汇编函数&调用约定

    探究如何在C语言里直接自写汇编函数 裸函数 裸函数与普通函数的区别 普通函数在经过编译器编译时,编译器自动生成保护现场,恢复现场等反汇编代码 当我们想要自己实现函数内部的汇编代码时,就可以告诉汇编器不 ...

  5. 【STM8】SPI通讯

    这篇内容有点长,如果有人想透过我的博客学习STM8的SPI,那是我的荣幸 首先我要先说大纲,这样大家心里比较有底,可以把精力都用在SPI理解上 [SPI初步介绍]:介绍SPI如何接线.名称解释.通讯注 ...

  6. Linux学习 - 正则表达式

    一.正则表达式与通配符 正则表达式:在文件中匹配符合条件的字符串,正则是包含匹配 通配符:用来匹配符合条件的文件名,通配符是完全匹配 二.基础正则表达式 元字符 作用 a* a有0个或任意多个 . 除 ...

  7. error信息

    /opt/hadoop/src/contrib/eclipse-plugin/build.xml:61: warning: 'includeantruntime' was not set, defau ...

  8. 出现 CannotAcquireLockException 异常

    项目出现  CannotAcquireLockException异常 原因: 百度了一下,是由于 Spring 事务嵌套造成死锁 结合自己的, handleWithdraw 方法底层有调用 其他 se ...

  9. mybatis分页插件PageHelper源码浅析

    PageHelper 是Mybaties中的一个分页插件.其maven坐标 <!-- https://mvnrepository.com/artifact/com.github.pagehelp ...

  10. Map集合的认识和理解

    java.util.Map(k,v)集合* Map的特点:* 1.Map集合是一个双列集合,一个元素包含两个值(一个是key,一个是Value)* 2.Map集合中的元素,key和value的类型可以 ...