当前位置:网站首页>Codeforces E. maximum subsequence value (greed + pigeon nest principle)
Codeforces E. maximum subsequence value (greed + pigeon nest principle)
2022-07-27 00:09:00 【Muxi Krystal】
https://codeforces.com/contest/1365/problem/E
( Title link above ↑)
The question :
from a Select a length of k The subsequence , Make the subsequence value Value is the largest . A subsequence value The value is 2^i And ,i Is the significant bit in binary form . If and only if there is no less than k-2 The binary of the number is 1 when , This bit is valid .
Answer key :
1. When k<=3 when , Only a valid bit of a number is needed to produce a contribution . So you can choose three numbers directly ,O(n^3) Enumerate all the cases , obtain value The maximum of .
2. When k>3 when , When a bit is valid , It means at least k-2 This bit of the number is 1, This situation is obviously more difficult to meet . But if you choose three numbers from this subsequence , Then according to the pigeon nest principle, there must be a number that is valid . Sum up ,k>3 Of the situation value Value is less than or equal to the result of selecting three numbers value value .
3. therefore , Greedily enumerate and select three numbers .
An operation :
0|0=0 0|1=1 1|0=1 1|1=1
so : value=ai | aj | ak
AC Code :
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[505];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
ll ans=0;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
for(int k=j;k<n;k++){
ans=max(a[i]|a[j]|a[k],ans);
}
}
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 文件上传到OSS文件服务器
- Baidu website Collection
- [C language] array
- 股票开户佣金是否可以调整?手机上开户安不安全
- Dynamic memory management
- 第3章 跨域问题
- Opencv camera calibration and distortion correction
- Tensorflow2.0 deep learning simple tutorial of running code
- Complete backpack and 01 Backpack
- The attorney general and the director of the national security service of Ukraine were dismissed
猜你喜欢

How to transfer the GPX data collected by CTI RTK out of KML and SHP with attributes for subsequent management and analysis

The basic operation of data tables in MySQL is very difficult. This experiment will take you through it from the beginning

Opencv camera calibration and distortion correction

uni-app学习(二)

Number that cannot be bought
![[C language] classic recursion problem](/img/97/a88626e1a42f3f425396592a77100d.png)
[C language] classic recursion problem

Azure Synapse Analytics 性能优化指南(3)——使用具体化视图优化性能(下)

买不到的数目

Re understand the life world and ourselves

第1章 拦截器入门及使用技巧
随机推荐
力扣141题:环形链表
push to origin/master was rejected 错误解决方法
Pytorch learning record (II): tensor
第7章 课程总结
文件上传到服务器
Section 6: introduction to cmake grammar
[Gorm] model relationship -hasone
[interview: concurrent Article 27: multithreading: hesitation mode]
Paging plug-in -- PageHelper
分页插件--PageHelper
Iptables prevent nmap scanning and binlog
Design of intelligent humidification controller based on 51 single chip microcomputer
Design of alcohol detector based on 51 single chip microcomputer
Practice of intelligent code reconstruction of Zhongyuan bank
2022.7.18-----leetcode.749
In simple terms, cchart daily lesson - happy high school lesson 57 new starting point, the old tree and new bud of colorful interface library
Tensorflow2.0 deep learning simple tutorial of running code
11_ Weather case - monitoring properties
Embedded system migration [8] - device tree and root file system migration
文件上传到OSS文件服务器