题目链接:

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. How to manually remove an infected file from your computer

    http://blog.csdn.net/pipisorry/article/details/41258577 How to manually remove an infected file from ...

  2. php对象序列化总出错false

    php unserialize 返回false的解决方法 php 提供serialize(序列化) 与unserialize(反序列化)方法. 使用serialize序列化后,再使用unseriali ...

  3. Centos7使用LVM扩容磁盘(测试成功)

    1.新增加了一块200G大小的磁盘/dev/sdb fdisk -l 2. pvcreate /dev/sdb 3. pvdisplay 查看添加成功的/dev/sdb的大小为200G 4. vgex ...

  4. Atitit.提升api兼容性的方法 v3 q326

    Atitit.提升api兼容性的方法 v3 q326 1. Atitit.兼容性的“一加三”策略1 2. 2. 扩展表模式1 3. 3. 同时运行模式1 3.1. 3.1. 完美的后向兼容性2 3.2 ...

  5. Atitit.单向sso  单点登录的设计与实现

    Atitit.单向sso  单点登录的设计与实现 1. 单点登录sso 的三大解决方案1 2. 新方案:密码管理器方案1 3. 调用方1 4. 自动登录登录2 5. 主页跳转2 1. 单点登录sso  ...

  6. 迁移TFS 2012服务至新的电脑硬件

    迁移TFS 2012的时候碰到一些问题, 中文记录很少, 英文的记录也比较零散. 这里记录最直接和简单的方法. 环境: 1. 公司域环境, 所有TFS用户都是公司域帐户. 2. TFS从一台服务器转移 ...

  7. scp命令的用法

    用法: scp 命令 scp 能够在 2个 linux 主机间拷贝文件: 命令基本格式: scp [可选參数] file_source file_target ====== 从 本地 拷贝到 远程 拷 ...

  8. 在CPU上运行Tensorflow

    如果你是用的GPU版本的Tensorflow,你可以这样来使用CPU版本的Tensorlfow: config = tf.ConfigProto( device_count = {'GPU': 0} ...

  9. 创建动作-Action:

    在Struts2的行动,唯一的要求是,必须有一个无参数的方法,该方法返回一个字符串或结果的对象,必须是一个POJO.如果不带参数的方法不指定,则默认行为是使用execute()方法. 您也可以选择扩展 ...

  10. #进阶系列——WebApi 身份认证解决方案:Basic基础认证

    阅读目录 一.为什么需要身份认证 二.Basic基础认证的原理解析 1.常见的认证方式 2.Basic基础认证原理 三.Basic基础认证的代码示例 1.登录过程 2./Home/Index主界面 3 ...