题意:

给出一系列值和对应的陷阱,对于陷阱如果存在两个就抵消,求价值最大。

思路:

折半枚举,利用异或

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; int v[30],k[30];
int trap[30][60],n,ans;
map<LL,int>mp;
map<LL,int>::iterator it;
int main()
{
while(~scanf("%d",&n))
{
ans=0;
mp.clear();
for(int i=0;i<n;i++)
{
scanf("%d",&v[i]);
scanf("%d",&k[i]);
for(int j=0;j<k[i];j++)
scanf("%d",&trap[i][j]);
}
int half=n/2;
int sz=(1<<half);
for(int i=0;i<sz;i++)
{
LL x=0;
int val=0;
for(int j=0;j<half;j++)
{
if(i&(1<<j))
{
for(int t=0;t<k[j];t++)
x^=(LL)(1LL<<trap[j][t]);
val+=v[j];
}
}
it=mp.find(x);
if(it!=mp.end())
{
int last=it->second;
if(last<val)
mp[x]=val;
}
else
mp[x]=val;
}
int res=n-half;
sz=(1<<res);
for(int i=0;i<sz;i++)
{
LL x=0;
int val=0;
for(int j=0;j<res;j++)
{
if(i&(1<<j))
{
for(int t=0;t<k[j+half];t++)
x^=(LL)(1LL<<trap[j+half][t]);
val+=v[j+half];
}
}
LL y=(0LL^x);
it=mp.find(y);
if(it!=mp.end())
{
int now=it->second;
val+=now;
ans=max(ans,val);
}
}
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. jQuery解决iframe高度自适应代码
  2. Android 程序打包及签名
  3. Java 语句总结
  4. 区分DPI、分辨率(PPI)、图像的物理大小、像素宽度
  5. Linux php 中文乱码解决
  6. 理解 __declspec(dllexport)和__declspec(dllimport)
  7. C++ AfxBeginThread
  8. 新建maven工程时pom.xml报错
  9. Redis 学习笔记-入门
  10. position:sticky 定位 position:fixed
  11. 完全理解 Python 迭代对象、迭代器、生成器(转)
  12. 网络流24题——数字梯形问题 luogu 4013
  13. 定位bug的基本要求
  14. js异步回调
  15. WHY数学表达式的3D可视化
  16. transform带来的坑
  17. 【读书笔记】iOS-自动布局
  18. php无限分类 下拉框
  19. 查看sqlserver2008数据库服务器实例名称
  20. HADOOP与HDFS数据压缩格式

热门文章

  1. 创建spring管理的自定义注解
  2. angularJs-HelloWorld
  3. 【python】用python脚本Paramiko实现远程执行命令、下载、推送/上传文件功能
  4. 3D焦点图插件
  5. 解读 CSS 布局之水平垂直居中
  6. insert …select …带来的死锁问题
  7. B1/B2签证的有效期——对于B1/B2签证,停留期最长不超过183天
  8. docker镜像管理基础
  9. 【LeetCode】259 3Sum Smaller
  10. 【Lintcode】036.Reverse Linked List II