题面

题面

题解

一个方案合法,当且仅当选取的01串凑不出0.

因此就是要使得选取的01串全在线性基内,具体原因可以看这道题:[CQOI2013]新Nim游戏 线性基

要使得魔力值最大,只需要按法力值从大到小,贪心的往线性基中加串就可以了

#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 1100
#define LL long long int n; LL ans;
LL f[AC];
struct node{LL x, w;}s[AC];
inline bool cmp(node a, node b){return a.w > b.w;} inline LL read()
{
LL x = 0;char c = getchar();
while(c > '9' || c < '0') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
} void pre()
{
n = read();
for(R i = 1; i <= n; i ++) s[i].x = read(), s[i].w = read();
sort(s + 1, s + n + 1, cmp);
} void work()
{
for(R i = 1; i <= n; i ++)//从高开始贪心
{
LL x = s[i].x, maxn = 1LL << 60; bool done = false;
for(R j = 60; ~j; j --, maxn >>= 1)
{
if(!(x & maxn)) continue;
if(!f[j]) {f[j] = x, done = true; break;}
else x ^= f[j];
}
if(done) ans += s[i].w;//加入线性基就要拿走
}
printf("%lld\n", ans);
} int main()
{
// freopen("in.in", "r", stdin);
pre();
work();
// fclose(stdin);
return 0;
}

最新文章

  1. HTML5 学习笔记(三)——本地存储
  2. 【吐槽】IM群里几种我认为愚蠢的提问方式
  3. Activity与Service进行数据交互
  4. (实用篇)PHP中单引号与双引号的区别分析
  5. 使用JDBC获取各数据库的Meta信息——表以及对应的列
  6. CodeForces 489B (贪心 或 最大匹配) BerSU Ball
  7. 完美让IE兼容input placeholder属性的jquery实现
  8. 关于 submit 按钮的 onclick 验证事件,第一次验证失败,第二次 submit 按钮失效的原因解析
  9. 访问祖先类的虚方法(直接访问祖先类的VMT,但是这种方法在新版本中未必可靠)
  10. 从ASP.NET Web API 2 (C#)开始说起
  11. web.confgi转换,web发布时发布配置(debug/release)生成不同的配置文件
  12. 基于python的知乎开源爬虫 zhihu_oauth使用介绍
  13. x86-64栈帧中的“红色区域” red zone of stack frame on x86-64
  14. 第三章 go语言 程序的流程控制
  15. mybatis入门系列二之输入与输出参数
  16. HTTP 方法:Get与Post分析
  17. salt stack 远程命令
  18. Unity另外一套简单日志控制系统
  19. Singular value encountered in calculation for ROI
  20. SQL语句的执行顺序 1&gt;优先执行,然后依数字排序

热门文章

  1. centOS上安装最新git 2.4.0
  2. Unity LineRenderer制作画版
  3. 解析build.gradle文件
  4. AtCoder Grand Contest 026 D - Histogram Coloring
  5. Ubuntu系统下在PyCharm里用virtualenv集成TensorFlow
  6. 用 Python 编写的 Python 解释器
  7. 一个小时搭建一个全栈 Web 应用框架
  8. PowerShell自定义修改远程桌面RDP端口
  9. Yii2 yii\helpers\ArrayHelper
  10. Farm Irrigation ZOJ 2412(DFS连通图)