设最大的数为$w$,若$n>k+\log w$,那么显然所有$1$都可以保留,否则现在$n\leq k+\log w$。

如果$w\leq 100000$,那么可以DP,设$f[i][j]$表示考虑前$i$个数,保留的数的$or$是$j$时,最多能删除多少个数,时间复杂度$O(nw)$。

如果$w>100000$,那么$k\leq 7$,爆搜即可,时间复杂度$O(C(n,k))$。

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int n,m,i,j,o,ans,mx,f[2][131100],a[N];
void dfs(int x,int y,int z){
if(y+n-x+1<m)return;
if(x>n){
ans=max(ans,z);
return;
}
dfs(x+1,y,z|a[x]);
if(y<m)dfs(x+1,y+1,z);
}
int main(){
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)scanf("%d",&a[i]),mx=max(mx,a[i]);
if(n>m+31){
for(i=1;i<=n;i++)ans|=a[i];
return printf("%d",ans),0;
}
if(mx<=100000){
for(i=0;i<131072;i++)f[0][i]=-N;
f[0][0]=0;
for(i=o=1;i<=n;i++,o^=1){
for(j=0;j<131072;j++)f[o][j]=f[o^1][j]+1;
for(j=0;j<131072;j++)if(f[o^1][j]>=0)f[o][j|a[i]]=max(f[o][j|a[i]],f[o^1][j]);
}
for(i=131071;~i;i--)if(f[o^1][i]>=m)break;
return printf("%d",i),0;
}
dfs(1,0,0);
return printf("%d",ans),0;
}

  

Ural2110 : Remove or Maximize的更多相关文章

  1. QT自绘标题和边框

    在QT中如果想要自绘标题和边框,一般步骤是: 1) 在创建窗口前设置Qt::FramelessWindowHint标志,设置该标志后会创建一个无标题.无边框的窗口. 2)在客户区域的顶部创建一个自绘标 ...

  2. How to remove a Data Guard Configuration from Primary Database (文档 ID 733794.1)

    APPLIES TO: Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.3 [Release 10.1 to 11. ...

  3. EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解

    前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...

  4. [LeetCode] Remove K Digits 去掉K位数字

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  5. [LeetCode] Remove Duplicate Letters 移除重复字母

    Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...

  6. [LeetCode] Remove Invalid Parentheses 移除非法括号

    Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...

  7. [LeetCode] Remove Linked List Elements 移除链表元素

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  8. [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  9. [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

随机推荐

  1. asp.net core 验证码方案

    /// <summary> /// 图片验证码 /// </summary> public class VerificationCodeServices { /// <s ...

  2. zabbix 3.2.4 使用详解

    一:zabbix简介及原理 二:zabbix添加主机: /usr/share/zabbix/include/locales.inc.php   #这里为zabbix语言包路径‘zh_CN’ 为true ...

  3. python functools

    # 工具函数import functools print(dir(functools)) # partial函数(偏函数)def showarg(*args,**kw): print(args) pr ...

  4. 'mysql' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    1.C:\Users\Aiyufei>mysql -h 127.0.0.1 -u root'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件.解决方法: 配置环境变量即可,我的问 ...

  5. Eclipse Memory Analyzer

    先写一段可以制造堆溢出的代码 package com.test.jvm.oom; import java.util.ArrayList; import java.util.List; /** * @d ...

  6. [转] getBoundingClientRect判断元素是否可见

    getBoundingClientRect介绍 getBoundingClientRect获取元素位置 getBoundingClientRect用于获得页面中某个元素的左,上,右和下分别相对浏览器视 ...

  7. 【BZOJ3252】攻略

    题解: 首先贪心的会发现我们每次一定会选当前权值和最大的那个 然后在于怎么维护这个最大值 我们发现每个修改实际上是对沿途所有点的子树的修改 所以用线段树维护就可以了.. 另外注意有重复部分,但一定是包 ...

  8. C# 之 比较两个word文档的内容

    利用 Microsoft.Office.Interop.Word 组件进行比较.引入命名空间:using Word2013 = Microsoft.Office.Interop.Word; 代码如下: ...

  9. Spring Security 架构与源码分析

    Spring Security 主要实现了Authentication(认证,解决who are you? ) 和 Access Control(访问控制,也就是what are you allowe ...

  10. 51Nod1309 Value of all Permutations 期望

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1309.html 题目传送门 - 51Nod1309 题意 长度为N的整数数组A,有Q个查询,每个查询 ...