Problem Statement

Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is Ai and has a utility of Bi. There may be multiple equal integers with different utilities.

Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.

Find the maximum possible sum of utilities of purchased integers.

解题报告:

这题从物品下手不好做,可以考虑从k下手,所以我们枚举最后的答案,一定是小于等于k的,所以直接枚举比k小的集合,这样的集合是很多的,但很多可以归为一类,我们这样归类:首先一个小于等于k的数一定是前面部分和k相同或更小,然后某一位k是1,而答案是0,所以枚举这一位作为分类的依据,只要是答案子集的都计入贡献,取Max即可

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=100005;
int n,m;
struct node{
int x,y;
}a[N];
ll ans=0;
void work()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
ll tot=0,li=0;m++;
for(int i=30;i>=0;i--){
if(m&(1<<i)){
li^=(1<<i);tot=0;
for(int j=1;j<=n;j++)
if((a[j].x&li)==0)tot+=a[j].y;
ans=Max(tot,ans);
li^=(1<<i);
}
else li^=(1<<i);
}
printf("%lld\n",ans);
} int main()
{
work();
return 0;
}

最新文章

  1. NSIS 无边框移动问题总结笔记
  2. 【原创】Linux常用管理命令总结
  3. LF CRLF
  4. squid3.0 隐藏 hearder 设置
  5. asp发布至IIS
  6. 常用分组函数count-avg-sum-max-min
  7. Linux 时间定时同步操作
  8. 原因好消息: PSP游戏自己主动算法设计(两)
  9. \t 的理解
  10. 拓扑排序&lt;反向拓扑+有向环的判断&gt;
  11. 每天4亿行SQLite订单大数据测试(源码)
  12. html学习中
  13. 微信h5 video的问题
  14. django——模板层
  15. django 表单使用
  16. go标准库的学习-strings-字符串操作
  17. 【转】mysql给root开启远程访问权限,修改root密码
  18. hibernate中的sql 1+n 问题
  19. Net分布式系统整体框架
  20. redis windows dll 下载

热门文章

  1. Java Client/Server 基础知识
  2. appiun滑动的简单封装
  3. Oracle闪回技术
  4. vue jsx 使用指南
  5. SQL Server元数据损坏(metadata corruption)修复
  6. MSIL实用指南-生成if...else...语句
  7. springboot字符集乱码
  8. RocketMQ(五):namesrv初探
  9. python爬虫动态html selenium.webdriver
  10. 简单了解Spring的控制反转和依赖注入