t组数据

n个汉堡 e的能量

接下来的2行

val    n个 得到的权

cost  n个 花去的能量

接下来n行

每行一个q  q个数字

代表这类汉堡做好要的前提  每个汉堡只能用一次

#include<stdio.h>
#include<algorithm>
#include<string.h> using namespace std; #define MAXN 1<<15
int dp[MAXN];
int val[],co[];
int x[];
int cost[MAXN];
int n,e; void Init() //预处理出所有状态要的能量
{
int en=(<<n);
for(int i=;i<en;i++)
{
for(int j=;j<n;j++)
{
if((i&(<<j)))
cost[i]+=co[j];
}
}
}
bool jud(int state,int p) //判断这个状态是否合法
{
if((state&x[p])==x[p]&&cost[state]+co[p]<=e)
return ;
return ;
}
int main()
{
int t;
scanf("%d",&t); while(t--)
{ scanf("%d%d",&n,&e);
memset(dp,-,sizeof(dp));
memset(cost,,sizeof(cost));
memset(x,,sizeof(x)); for(int i=;i<n;i++)
scanf("%d",&val[i]);
for(int i=;i<n;i++)
scanf("%d",&co[i]);
for(int i=;i<n;i++)
{
int a;
scanf("%d",&a);
for(int j=;j<=a;j++)
{
int b;
scanf("%d",&b);
b--;
x[i]|=(<<b);
}
}
Init();
int ans=;
dp[]=;
int en=(<<n);
for(int i=;i<en;i++)
{
if(dp[i]!=-)
for(int j=;j<n;j++)
{
if(jud(i,j)&&(i&(<<j))==) /这个汉堡可以做
{
dp[i|(<<j)]=dp[i]+val[j]; //前面的权值+这个的权
ans=max(ans,dp[i|(<<j)]);
}
}
}
printf("%d\n",ans);
}
return ;
}

状态压缩 HDU 3182的更多相关文章

  1. 状态压缩 HDU 1565

    多组数据 给你一个n*n的矩阵 不能相邻的取数 上下左右 求最大的和 #include<stdio.h> #include<algorithm> #include<str ...

  2. 状态压缩 HDU 3091

    多组数据 n个点m条边 求有几个经过所有的点的环 最好用__int64 #include<stdio.h> #include<algorithm> #include<st ...

  3. 状态压缩 hdu #10

    You are playing CSGO. There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose ...

  4. HDU 3605:Escape(最大流+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

  5. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  6. ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

    HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & ...

  7. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

  8. HDU 4511 (AC自动机+状态压缩DP)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...

  9. hdu 2825(ac自动机+状态压缩dp)

    题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...

随机推荐

  1. POJ 1556 The Doors【最短路+线段相交】

    思路:暴力判断每个点连成的线段是否被墙挡住,构建图.求最短路. 思路很简单,但是实现比较复杂,模版一定要可靠. #include<stdio.h> #include<string.h ...

  2. 向tiny6410中移植中移植linux-4.5.1内核(最新)

    下载linux-4.5.1.tar.gz 解压在任意目录下.我解压在/home/tiny6410/ # tar xvzf linux-4.5.1.tar.gz # cd linux-4.5.1/ 修改 ...

  3. Visio连接数据表实体外键[快捷记录]

    打开数据库模型图. 单击“常用”工具栏上的“连接线”工具. 将“连接线”工具放在父表的中心上,使表的四周出现轮廓线,然后拖到子表的中心.当子表出现轮廓线时,松开鼠标按钮. 两个连接点均变为红色,同时父 ...

  4. QuickFix/J 源代码

    三). 客户化FIX解析 基础知识:以下文章内容描述的前提是已经根据自己的业务规则,生成了符合要求的数据字典,并且使用QuickFix/J自带的 ant 的 jar target生成了客户化的协议解析 ...

  5. [No000028]Python的使用之禅及程序员应该明白的一些道理

    最近疯狂的学习ruby和python着两门语言,看到书本上一些比较赞同的段子,摘抄并翻译如下: Python的使用之禅 Beautiful is better than ugly. 美丽好过丑陋Exp ...

  6. git push上传代码到gitlab上,报错401或403

    之前部署的gitlab代码托管平台,采用ssh方式连接gitlab,在客户机上产生公钥上传到gitlab的SSH-Keys里,则git clone下载和git push上传都没问题,这种方式很安全. ...

  7. Docker简明教程(以安装wget程序为例)

    本文计划: 一.安装Docker(Centos) 二.注册Docker官网帐号 三.下载基础centos镜像,安装需要的软件和环境后,push到自己的repository 一.安装Docker(Cen ...

  8. jquery 添加节点的几种方法介绍

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  9. css中如何设置字体

    来自百度的回答: 建议使用font-family: "Microsoft YaHei";支持UTF-8和GB2312字符集. 不生效的3种情况:1.当此属性定义的是全局样式时,对于 ...

  10. linux传输大文件

    http://dreamway.blog.51cto.com/1281816/1151886 linux传输大文件