Tenka1 Programmer Contest D - IntegerotS

时间:2022-09-22 23:43:59

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;
}

Tenka1 Programmer Contest D - IntegerotS的更多相关文章

  1. Atcoder Tenka1 Programmer Contest D&colon; IntegerotS 【思维题,位运算】

    http://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_d 给定N,K和A1...AN,B1...BN,选取若干个Ai使它们的或运算值小于等于K ...

  2. 【AtCoder】Tenka1 Programmer Contest 2019

    Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...

  3. Tenka1 Programmer Contest D - Crossing

    链接 Tenka1 Programmer Contest D - Crossing 给定\(n\),要求构造\(k\)个集合\({S_k}\),使得\(1\)到\(n\)中每个元素均在集合中出现两次, ...

  4. Tenka1 Programmer Contest C - Align

    链接 Tenka1 Programmer Contest C - Align 给定一个序列,要求重新排列最大化\(\sum_{i=2}^{i=n} |a_i-a_{i-1}|\),\(n\leq 10 ...

  5. 【AtCoder】Tenka1 Programmer Contest

    C - 4/N 列出个方程枚举解一下 #include <bits/stdc++.h> #define fi first #define se second #define pii pai ...

  6. Atcoder Tenka1 Programmer Contest C C - 4&sol;N

    http://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_c 我怀疑我是不是智障.... 本来一直的想法是能不能构造出答案,把N按奇偶分,偶数好办 ...

  7. Tenka1 Programmer Contest 2019

    C:即要使前一部分为白色后一部分为黑色,枚举分割点前缀和计算答案取min即可. #include<bits/stdc++.h> using namespace std; #define l ...

  8. Atcoder Tenka1 Programmer Contest 2019

    C 签到题,f[i][0/1]表示以i结尾最后一个为白/黑的最小值,转移显然. #include<bits/stdc++.h> using namespace std; ; ]; char ...

  9. 【AtCoder】Tenka1 Programmer Contest&lpar;C - F&rpar;

    C - Align 考的时候,我大胆猜了结论,就是一小一大一小一大这么排 证明的话,由于我们总是要加上相邻的最大值而减去最小值,我们就让最大值都保持在前面 如果长度为奇数,要么就是大小大小大,要么是小 ...

随机推荐

  1. com学习前提必看

    1) COM组件实际上是一个C++类,而接口都是纯虚类.组件从接口派生而来.我们可以简单的用纯粹的C++的语法形式来描述COM是个什么东西: class IObject { public: virtu ...

  2. Shell遍历文件的每一行&lbrack;转载&rsqb;

    #!/bin/sh while read line do echo $line done < /home/jms/lab/input.txt

  3. to disable the entity lazy load&comma; The ObjectContext instance has been disposed and can no longer be used for operations that require a connection&period;

    The ObjectContext instance has been disposed and can no longer be used for operations that require a ...

  4. javascript模板引擎template&period;js使用

    到GitHub上下载template.js库.引入到页面 以type="text/html" 这样指定javascript类型的是一种javascript模板渲染方法,在实际项目中 ...

  5. 剑指offer 11&period; 位运算 二进制中1的个数

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示.   //思想:用1(1自身左移运算,其实后来就不是1了)和n的每位进行位与,来判断1的个数     private stat ...

  6. &lbrack;C&rsqb;&ast;和&amp&semi;

    一 .& c的&被称为“寻址运算符”,作用是指向某变量的指针: 请看以下代码: int main(void){ int int_1 = 16;        printf(" ...

  7. xp上使用vsphere client报错问题

    出现该问题的原因是新版本的esxi和vcenter中增强了加密强度,而Windows XP和Windows Server 2003未能达到所需加密强度,client发起的链接被esxi和vcenter ...

  8. HTML(二):表格元素

    表格元素的作用:用来格式化显示数据. 一.表格的基本结构 表格的基本语法:<TABLE border="设置表格边框尺寸大小" width="" cell ...

  9. 界面设计中如何增强CTA按钮召唤力?

    以下内容由Mockplus(摹客)团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 网页和软件应用之类数字产品的有效交互系统一般是由拥有各种任务和功能的小元素构成.而为创建更加 ...

  10. outlook2013插件 VSTO开发与部署

    一.背景 最近因为项目需要对outlook开发一个插件,功能是将outlook的邮件作导出功能,需要使用VSTO开发一个插件将邮件进行导出的操作.于是,开始学习VSTO outlook的开发了,折腾了 ...