题目链接:

pid=3182">http://acm.hdu.edu.cn/showproblem.php?pid=3182

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
 
Source

//题意:

//一个人做汉堡包,每一个汉堡包都有自己的花费和价值,

某些汉堡包必需要在其它的某一些汉堡包已经做好了的前题下才干制作,

给出这个人的初始钱数。问能实现的最大价值是多少。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 17;
int a[maxn][maxn];//须要满足的做汉堡包的先后顺序
int dp[1<<maxn];//dp[i]表示i状态时的最大价值,
int no_cost[1<<maxn];//no_cost[i]表示的是i状态时的剩余的钱
int cost[maxn], get_v[maxn];
int n, money;
int judge(int m, int state)
{
//检查是否满足做某汉堡包时题目给出的要在做他之前做的汉堡包都已经做了
for(int i = 1; i <= a[m][0]; i++)
{
if(!(state & (1<<(a[m][i]-1))))
{
return 0;
}
}
return 1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&money);
for(int i = 1; i <= n; i++)
{
scanf("%d",&get_v[i]);
}
for(int i = 1; i <= n; i++)
{
scanf("%d",&cost[i]);
}
int tt;
for(int i = 1; i <= n; i++)
{
scanf("%d",&a[i][0]);
for(int j = 1; j <= a[i][0]; j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i = 0; i <= (1<<n)-1; i++)
{
dp[i] = -1111;
no_cost[i] = 0;
}
dp[0] = 0;
no_cost[0] = money;
int ansm = 0;
for(int i = 0; i <= (1<<n)-1; i++)
{
for(int j = 1; j <= n; j++)
{
if(i & 1<<(j-1))//假设第i个汉堡包已经做过就不再更新
{
continue;
}
int now = i | (1<<(j-1));//做第i个汉堡包
if(dp[now] < dp[i]+get_v[j] && judge(j,i) && no_cost[i] >= cost[j])
{
dp[now] = dp[i]+get_v[j];
no_cost[now] = no_cost[i] - cost[j];
ansm = max(ansm, dp[now]);
}
}
}
printf("%d\n",ansm);
}
return 0;
}

HDU 3182 Hamburger Magi(状压dp)的更多相关文章

  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 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  3. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. hdu_3182_Hamburger Magi(状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前 ...

  5. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  6. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  7. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

  8. hdu 4856 Tunnels (bfs + 状压dp)

    题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...

  9. HDU 4272 LianLianKan (状压DP+DFS)题解

    思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...

  10. HDU 3362 Fix (状压DP)

    题意:题目给出n(n <= 18)个点的二维坐标,并说明某些点是被固定了的,其余则没固定,要求添加一些边,使得还没被固定的点变成固定的, 要求总长度最短. 析:由于这个 n 最大才是18,比较小 ...

随机推荐

  1. 36氪Plus消息:贷款组合推荐工具“钱小二”已获数百万天使轮融资

    根据"钱小二"在创业者社区36氪plus上的更新信息,该团队已获得数百万天使轮融资,投资方及投资时间不明. "钱小二"是一个贷款搜索 + 贷款组合推荐平台,目标 ...

  2. 可以打开QQ,但打不开网页的DNS服务器设置问题

    方法二: IE->设置->连接->局域网设置

  3. ISA2006安装和部署基础(虚拟机非域环境)

    0x00. 为了測试基于HTTP隧道的绕过ISA,必须搭建模拟环境,为了不麻烦,我们这里不配合域环境认证.本次实验利用Vmware 10.0搭建好开发环境,实现ISA2006安装和部署,同一时候设定基 ...

  4. url传递参数

    url:'/randowCode?t='+Math.random(); //当给某个赋值可以: $('#change').click(function(){ $("#codeimage&qu ...

  5. hive 添加UDF(user define function) hive的insert语句

    add JAR /home/hadoop/study/study2/utf.jar; package my.bigdata.udf; import org.apache.hadoop.hive.ql. ...

  6. 大数据(6) - MapReduce简易介绍入门

    一 MapReduce入门 MapReduce定义(简单来说就是hadoop的数据分析核心,理解其中的原理,则可以分析聚合一切需求) Mapreduce是一个分布式运算程序的编程框架,是用户开发“基于 ...

  7. Elasticsearch5.X IN Windows 10 系列文章(2)

    ElasticSearch版本: 5.5.1 (最新稳定版为5.5.2),由于用到IK中文分词插件,最新版本没有5.5.2 ,所以使用5.5.1 日期:2017-08-29 第二章:安装Kibana ...

  8. android:clearTaskOnLaunch的用法

    比如你的应用里有N个Activity,其中有个是设置页面,你从主页面进入到设置页面设置了一些东西之后,突然,按了下Home键,回到了Android的Home,这时候你做了些别的事情,然后你再次点击你的 ...

  9. Photoshop脚本之jpg转换成eps

    function saveEPS( doc, saveFile ) { var saveOptions = new EPSSaveOptions( ); saveOptions.encoding = ...

  10. 在eclipse中使用枚举简单类型enum

    在JAVA中终于可以使用枚举类型了,就像在C或C++使用的简单枚举. 首先就在eclipse中试试它吧. 没想到,却报了错误.我装了jdk1.5(5.0),也在eclipse中设置了,怎么会不认识en ...