AT4168 [ARC100C] Or Plus Max
从\(whk\)回来了。
考虑我们需要维护一个子集的信息。
对于二进制的子集信息维护有一个很经典的操作:
高维前缀和。
AT4168 [ARC100C] Or Plus Max
// Problem: AT4168 [ARC100C] Or Plus Max
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/AT4168
// Memory Limit: 1000 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#define ll long long
#define N 1000005
struct P{
int mx1,mx2;
}f[N];
ll n;
int main(){
scanf("%lld",&n);
for(int i = 0;i <= (1 << n) - 1;++i){
ll x;
scanf("%lld",&x);
f[i].mx1 = x;
f[i].mx2 = 0;
}
for(int i = 0;i <= n - 1;++i){
for(int j = 0;j <= (1 << n) - 1;++j){
if(j & (1 << i)){
int to = j ^ (1 << i);
P k;
if(f[j].mx1 > f[to].mx1){
k.mx1 = f[j].mx1;
k.mx2 = std::max(f[to].mx1,f[j].mx2);
}
else{
k.mx1 = f[to].mx1;
k.mx2 = std::max(f[to].mx2,f[j].mx1);
}
f[j] = k;
}
}
}
ll ans = 0;
for(int i = 1;i <= (1 << n) - 1;++i)
std::cout<<(ans = std::max(ans,(ll)f[i].mx1 + f[i].mx2))<<std::endl;
}
AT4168 [ARC100C] Or Plus Max的更多相关文章
- Kafka副本管理—— 为何去掉replica.lag.max.messages参数
今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...
- 排序算法----基数排序(RadixSort(L,max))单链表版本
转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- [LeetCode] Max Points on a Line 共线点个数
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- supervisor监管进程max file descriptor配置不生效的问题
配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile 单独起进程没问题, 放到supervisor下监管启动,则报错 ...
- Max double slice sum 的解法
1. 上题目: Task description A non-empty zero-indexed array A consisting of N integers is given. A tripl ...
- 3ds max 渲染清晰面片的边缘
3ds max的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.
- sql中NVARCHAR(MAX) 性能和占空间分析 varchar(n),nvarchar(n) 长度性能及所占空间分析
varchar(n),nvarchar(n) 中的n怎么解释: nvarchar(n)最多能存n个字符,不区分中英文. varchar(n)最多能存n个字节,一个中文是两个字节. 所占空间: nvar ...
随机推荐
- SyntaxError: Non-UTF-8 code starting with '\xbb' in file D:\流畅学python\ex32.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
1. 报错如下: SyntaxError: Non-UTF-8 code starting with '\xd3' in file D:\流畅学python\ex34.py on line 4, bu ...
- javascript-原生-面向对象
1.javascript面向对象程序设计 概述:javascript不想其他面向对象编程语言那样有类的概念,javascript没有类(构造函数)的概念,只有对象的概念. 2.理解javascript ...
- logstash处理多行日志-处理java堆栈日志
logstash处理多行日志-处理java堆栈日志 一.背景 二.需求 三.实现思路 1.分析日志 2.实现,编写pipeline文件 四.注意事项 五.参考文档 一.背景 在我们的java程序中,经 ...
- dice_game攻防世界进阶区
dice_game XCTF 4th-QCTF-2018 前言,不得不说,虽然是个简单题但是还是要记录一下,来让自己记住这些东西. 考察的知识点是: 1.cdll_loadlibrary加载对应库使得 ...
- Noip模拟33垫底反思 2021.8.8
T1 Hunter 考场上没写$%p$挂了25分.也是很牛皮,以后打完过了样例一定要检查 因为样例太小了......很容易忘记%%%% 正解随便手模就出来了. 1 #include<bits/s ...
- 单片机STM32的5个时钟源知识
众所周知STM32有5个时钟源HSI.HSE.LSI.LSE.PLL,其实他只有四个,因为从上图中可以看到PLL都是由HSI或HSE提供的. 其中,高速时钟(HSE和HSI)提供给芯片主体的主时钟.低 ...
- tar 解压分割压缩文件
被分割后的压缩文件必须先合并成一个压缩文件才能正常的解压. 第一步.合并压缩文件 第二步.正常解压 $ls TINA-1.3.tar.gzaa TINA-1.3.tar.gzab TINA-1.3.t ...
- c++中virtual 虚函数
转载: https://www.cnblogs.com/weiyouqing/p/7544988.html 在面向对象的C++语言中,虚函数(virtual function)是一个非常重要的概念. ...
- Python 语法错误 except Exception, e: ^ SyntaxError: invalid syntax
出这个问题是因为python2和python3 语法有些不同 python2 和 3 处理 except 子句的语法有点不同,需要注意: Python2 try: print ("hello ...
- reorder-list leetcode C++
Given a singly linked list L: L 0→L 1→-→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→- You ...