题目链接:

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. [ci]安装配置jenkins及其插件

    后面尝试ms模式部署多台jenkins 安装jenkins:(hudson是jenkins的商业版) cd /etc/yum.repos.d/ wget http://pkg.jenkins.io/r ...

  2. Spring 读取配置文件(一)

    注册 @Configuration 标识的类,spring 读取配置文件的时候该类会被自动装载 package cn.com.receive;import org.springframework.be ...

  3. Python学习之格式符

    %s    字符串 (采用str()的显示) %r    字符串 (采用repr()的显示) %c    单个字符 %b    二进制整数 %d    十进制整数 %i    十进制整数 %o    ...

  4. [开源]C#中开源软件大汇总(外国的)

    一.博客类项目 1.SubText 项目介绍:Subtext 是一个个人博客发布平台,详细的介绍请进SubText 项目分类:博客 项目license:BSD License 项目主页:http:// ...

  5. cookie做订单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. android:clearTaskOnLaunch的用法

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

  7. shell学习五十八天----/proc文件系统

    /proc文件系统 前言:linux中的/proc文件系统,由一组文件夹和文件组成,挂载(mount)与/proc文件夹下. /proc文件系统是一种虚拟文件系统,以文件系统文件夹和文件形式,提供一个 ...

  8. 数据库 : Mysql - 日常应用

    #登录MYSQL数据库 MYSQL -u root -p #显示所有数据库 SHOW databases; #显示当前数据库与应用程序间进行了多少条连接 SHOW processlist; #使用某一 ...

  9. js 触摸事件 touch

    //ban 为某div let startX = 0; ban.addEventListener("touchstart",function(){ //获取初始点击位置 start ...

  10. java中通过配置文件的方式(Jedis驱动)使用Redis

    在java中使用Redis,实际上是将Redis的一些命令封装到Jedis的实体类中,然后进行调用.