状态压缩 HDU 3182
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的更多相关文章
- 状态压缩 HDU 1565
多组数据 给你一个n*n的矩阵 不能相邻的取数 上下左右 求最大的和 #include<stdio.h> #include<algorithm> #include<str ...
- 状态压缩 HDU 3091
多组数据 n个点m条边 求有几个经过所有的点的环 最好用__int64 #include<stdio.h> #include<algorithm> #include<st ...
- 状态压缩 hdu #10
You are playing CSGO. There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩
HDU 5418 Victor and World Time Limit:2000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
- HDU 4511 (AC自动机+状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...
- hdu 2825(ac自动机+状态压缩dp)
题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...
随机推荐
- 第30课 Qt中的文本编辑组件
1. 3种常用的文本编辑组件的比较 单行文本支持 多行文本支持 自定义格式支持 富文本支持 QLineEdit (单行文本编辑组件) Yes No No No QPlainTextEdit (多行普通 ...
- 移动前端UI选择
移动前端UI选择 目录 三.SUI Mobile 一.jQuery Mobile jQuery Mobile 是jQuery在移动设备上的版本,做为主要针对移动设备的框架来说,它提供一个移动设备平 ...
- 学习cocos code ide 的lua编程
装上了cocos code ide,配了路径之后,建立一个默认lua工程,发现无法调试,报错. 问了别人,在cocos2dconstants.lua的613行插入cc.AsyncTaskPool = ...
- CSS3硬件加速需要注意的事项
webkit浏览器会把所有需要动画的元素放到复合层中渲染,另外以下两种情况也会使不需要动画的元素也放到复合层中渲染,这样会导致元素动画不流畅(原则是需要的动画才让它在复合层中渲染) 1,元素有一个包含 ...
- XAMPP部署
1,直接从官网上下载,然后安装即可 2,出现的问题: a,启动Apache服务器的时候,出现打开端口失败,原因80号端口已被占用,解决方案,更改config文件,将端口设置为8090 b,给phpmy ...
- 编写更少量的代码:使用apache commons工具类库
Commons-configuration Commons-FileUpload Commons DbUtils Commons BeanUtils Commons CLI Commo ...
- 解决Kafka-1194问题
生产环境中使用Kafka作为日志处理的中间件,系统结构是这样的.自12月上线一个多月来,系统运行稳定. 用过kafka的都知道,Kafka产生的消息全部存储到硬盘文件中,并且在消息被消费后不会被立即删 ...
- CentOs中mysql的安装与配置
在linux中安装数据库首选MySQL,Mysql数据库的第一个版本就是发行在Linux系统上,其他选择还可以有postgreSQL,oracle等 在Linux上安装mysql数据库,我们可以去其官 ...
- bootstrap-datepicker带中文的js文件
) { $(".datepicker").datepicker({ language: "zh-CN", autoclose: true,//选中之后自动隐藏日 ...
- Eclipse利用Maven2搭建SpringMVC框架的Web工程
一.准备工作: 下载apache-maven--> 配置Maven_home -->下载Eclipse Maven插件 二.新建工程: 选择新建Maven Project arche ...