Ural2110 : Remove or Maximize
设最大的数为$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的更多相关文章
- QT自绘标题和边框
在QT中如果想要自绘标题和边框,一般步骤是: 1) 在创建窗口前设置Qt::FramelessWindowHint标志,设置该标志后会创建一个无标题.无边框的窗口. 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. ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- [LeetCode] Remove K Digits 去掉K位数字
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- [LeetCode] Remove Duplicate Letters 移除重复字母
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- [LeetCode] Remove Invalid Parentheses 移除非法括号
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
随机推荐
- K8s-Pod
一:Pod-资源对象概述 Pod是k8s系统中可以创建和管理的最小单元,是资源对象模型中由用户创建或部署的最小资源对象模型,也是在k8s上运行容器化应用的资源对象,其他的资源对象都是用来支撑或者扩展P ...
- 任务超时退出的方法 C#
超出时间方法退出.防止卡住. 方法: private static bool ImportTaskTimeout(Action method, int hours) { try { var task ...
- MySQL:日期函数、时间函数总结
MySQL 获得当前日期时间 函数 查询昨天,时间拼接 select concat(DATE_FORMAT(date_add(now(), interval -1 day),'%Y-%d-%d'),& ...
- iptables命令
iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分.可以直接配置,也可以通过许多前端和图形界面配置. 语法 iptables(选项)(参数) 选项 -t<表&g ...
- 删除Apache服务的命令
转到\Apache24\bin目录下,使用cmd命令sc delete apache2.2
- 将Elasticsearch的快照备份到HDFS
1.安装Elasticsearch插件repository-hdfs 下载地址:https://artifacts.elastic.co/downloads/elasticsearch-plugins ...
- Windows Azure 搭建网络代理 Proxy
额 题目起的有点大 其实就是在 Linux 上使用代理 不过是用的 Azure 上的 Liunx 虚拟机而已 如何在 Azure 上搭建 VPN 见上篇:http://www.cnblogs.com/ ...
- Python_自定义模块
自定义模块例子(web简单框架): 专门处理逻辑的包:处理各种访问需求 数据库的交互:面临各种的查询,删改 ,dba, 配置文件(全局配置文件):列存储数据的地方,HTML代码存储地方 实现: 代码: ...
- 扩展中国剩余定理 (exCRT) 的证明与练习
原文链接https://www.cnblogs.com/zhouzhendong/p/exCRT.html 扩展中国剩余定理 (exCRT) 的证明与练习 问题模型 给定同余方程组 $$\begin{ ...
- Codeforces 873F Forbidden Indices 字符串 SAM/(SA+单调栈)
原文链接https://www.cnblogs.com/zhouzhendong/p/9256033.html 题目传送门 - CF873F 题意 给定长度为 $n$ 的字符串 $s$,以及给定这个字 ...