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. POJ3013 Big Christmas Tree[转换 最短路]

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 23387   Accepted: 5 ...

  2. [No00000A]计算机的存储单位

    位 bit (比特)(Binary Digits):存放一位二进制数,即 0 或 1,最小的存储单位. 字节 byte:8个二进制[bit (比特)(Binary Digits)]位为一个字节(B), ...

  3. json格式的优点

    总结:1.占带宽小(格式是压缩的)2. js通过eval()进行Json读取(便于客户端读取)3. JSON支持多种语言(c.c++.php等),便于服务端解析 JSON (JavaScript Ob ...

  4. 线程 VS 进程

    线程是指进程内的一个执行单元,也是进程内的可调度实体. 与进程的区别: (1)地址空间:进程内的一个执行单元;进程至少有一个线程;它们共享进程的地址空间;而进程有自己独立的地址空间; (2)资源拥有: ...

  5. C语言操作文件

    #include <stdio.h> struct stu{ ]; int num; int age; ]; }boya[],boyb[]; struct stu *pa,*pb; mai ...

  6. js profiler

    https://developers.google.com/web/fundamentals/performance/critical-rendering-path/?hl=en https://de ...

  7. 二叉树的遍历(递归,迭代,Morris遍历)

    二叉树的三种遍历方法: 先序,中序,后序,这三种遍历方式每一个都可以用递归,迭代,Morris三种形式实现,其中Morris效率最高,空间复杂度为O(1). 主要参考博客: 二叉树的遍历(递归,迭代, ...

  8. jQuery学习笔记(四):attr()与prop()的区别

    这一节针对attr()与prop()之间的区别进行学习. 先看看官方文档是如何解释两者之间功能差异的: attr() Get the value of an attribute for the fir ...

  9. iptables规则组成

    一.四张表五条链 组成部分:四张表 + 5条链(Hook point) + 规则 四张表:filter nat mangle raw 五条链:PREROUTING INPUT FORWARD OUTP ...

  10. Sql server使用Merge关键字做插入或更新操作

    Merge是关于对于两个表之间的数据进行操作的. 要使用Merge的场景比如: 数据同步 数据转换 基于源表对目标表做Insert,Update,Delete操作 MERGE语句的基本语法: MERG ...