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. SQL主外键和子查询

    主键 数据库主键是指表中一个列或列的组合,其值能唯一地标识表中的每一行.这样的一列或多列称为表的主键,通过它可强制表的实体完整性.当创建或更改表时可通过定义 PRIMARY KEY约束来创建主键.一个 ...

  2. Mantis1.2.19 在Windows 平台上的安装配置详解

    安装环境: WindowsXP 32 Apache2.2.22+PHP5.4.39+MySQL5.5.28 一.简介 MantisBT是由PHP开发的.基于WEB的缺陷跟踪系统,并采用开源数据库MyS ...

  3. [No000018]都在背单词,为啥学霸那么厉害-如何在一天内记200个单词?

  4. java 24 - 4 GUI之创建数据转移窗口

    需求: 把文本框中的数据,通过点击按钮,转移到文本域中.  同时清空文本框中的数据 代码:(步骤都注释了) public class FrameDemo4 { public static void m ...

  5. C语言:关于socket的基础知识点

    /** * ---结构体--- * * #include <sys/socket.h> * struct sockaddr { * unsigned short sa_family; * ...

  6. PL/SQL Developer 11 64bit 安装和配置

    安装后, 1. 解压 instant client 到plsql developer 的安装目录    注意, 此版本只支持 instantclient_11_x, 不支持 instantclient ...

  7. Jersey the RESTful Web Services in Java

    Jersey 是一个JAX-RS的实现, JAX-RS即Java API for RESTful Web Services, 支持按照表述性状态转移(REST)架构风格创建Web服务. REST 中最 ...

  8. Sonatype Nexus Maven仓库搭建和管理

    安装 1. 从 http://www.sonatype.org/nexus/ 下载最新的 Nexus 压缩包, 现在已经不提供war包的下载 2. 解压到服务器目录, 例如我是放到/opt/nexus ...

  9. Meet Python: little notes

    Source: http://www.liaoxuefeng.com/ ❤ Escape character: '\' - '\n': newline; - '\t': tab; - '\\': \; ...

  10. SPM paired t-test步骤

    首先感谢大神空里流霜耐心的讲解,这篇笔记内容主要是整理他的谆谆教导,虽然他也看不到>< 所有数据都要经过平滑. Paired t-test虽然在2nd-level analysis中,但是 ...