HDU 3182 Hamburger Magi(状压dp)
题目链接: pid=3182">http://acm.hdu.edu.cn/showproblem.php?pid=3182
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
4 90
243 464 307 298
79 58 0 72
3 2 3 4
2 1 4
1 1
0
298
//题意:
//一个人做汉堡包,每一个汉堡包都有自己的花费和价值,
某些汉堡包必需要在其它的某一些汉堡包已经做好了的前题下才干制作,
给出这个人的初始钱数。问能实现的最大价值是多少。
代码例如以下:
#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)的更多相关文章
- HDU 3182 - Hamburger Magi - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu_3182_Hamburger Magi(状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前 ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
- HDU 3362 Fix (状压DP)
题意:题目给出n(n <= 18)个点的二维坐标,并说明某些点是被固定了的,其余则没固定,要求添加一些边,使得还没被固定的点变成固定的, 要求总长度最短. 析:由于这个 n 最大才是18,比较小 ...
随机推荐
- Atitit.java jna 调用c++ dll 的总结
Atitit.java jna 调用c++ dll 的总结 1. JNA技术解密1 1.1. JNA工作原理1 2. JNA技术难点 Java—C和操作系统数据类型的对应表1 2.1. 1 2.2. ...
- verilog语法注意部分
l generate语句 Verilog-2001添加了generate循环,允许产生module和primitive的多个实例化,同时也可以产生多个variable,net,task,functio ...
- Dig HOWTO 中文手册--dig命令使用大全
Dig HOWTO 中文手册--dig命令使用大全 DNS -- 本人翻译的dig howto手册. 译者序: 可以这样说,翻译本篇文档的过程就是我重新学习DNS的过程,dig命令可以帮助我们学习DN ...
- deepin linux下eclipse c/c++ 调试开源代码
1.deepin linux 下使用eclipse c/c++ 调试2. 编译选项,-g3 -O0,-g3表示输出调试信息,-O0不优化代码(第一个字母o的大写,第二个是数字0) 3.必备环境: gd ...
- 彻底解决maven Cannot change version of project facet Dynamic Web Module to 3.0?
这个问题是由于maven默认的jdk和默认的Dynamic Web Module版本问题引起的. 这个问题断断续续解决了复发了,今天找打了一个方法 第一,首先要在maven中配置这个插件 <pl ...
- quantz入门和使用流程(转载)
1.下载地址:http://quartz-scheduler.org/downloads/catalog http://quartz-scheduler.org/downloads/destinati ...
- 【spring boot】在spring boot下使用多线程
使用场景: 方法处理到某一步,需要将信息交给另一个线程去处理!! =================================================================== ...
- 第一百七十六节,jQuery,插件
jQuery,插件 学习要点: 1.插件概述 2.验证插件 3.自动完成插件 4.自定义插件 插件(Plugin)也成为 jQuery 扩展(Extension),是一种遵循一定规范的应用程序接口编 ...
- Chromium中多线程及并发技术要点(C/C++)
类别 类 说明 演示样例 线程机制 Thread (參考:线程模型及应用指南) MessagePump MessageQueue SequencedWorkerPool 它是一个线程池,用 ...
- jq中prop和attr的区别以及各自的使用
在高版本的jquery引入prop方法后,什么时候该用prop?什么时候用attr?它们两个之间有什么区别?这些问题就出现了. 关于它们两个的区别,网上的答案很多.这里谈谈我的心得,我的心得很简单: ...