当前位置:网站首页>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;
}
边栏推荐
- Share a regular expression
- [interview: concurrent Article 27: multithreading: hesitation mode]
- The attorney general and the director of the national security service of Ukraine were dismissed
- Part II - C language improvement_ 11. Pretreatment
- Identity server4 authorization successful page Jump encountered an error: exception: correlation failed Solution of unknown location
- 第1章 需求分析与ssm环境准备
- 12_ Binding style
- 11_ Weather case - monitoring properties
- In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter
- 4-4 对象生命周期
猜你喜欢

Dynamic memory management

3 esp8266 nodemcu network server

Part II - C language improvement_ 13. Recursive function

【C语言】经典的递归问题

文件上传到OSS文件服务器

Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one

上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬

Qunar travel massive indicator data collection and storage

Question 141 of Li Kou: circular linked list

C语言数组
随机推荐
Chapter 3 cross domain issues
Can the stock account opening commission be adjusted? Is it safe to open an account on your mobile phone
[2016] [paper notes] differential frequency tunable THz technology——
Oracle remote connection configuration
3 esp8266 nodemcu network server
Apple TV HD with the first generation Siri remote is listed as obsolete
力扣152题:乘积最大子数组
Hcip day 2_ HCIA review comprehensive experiment
[netding Cup 2018] Fakebook records
告别宽表,用 DQL 成就新一代 BI
文件上传到服务器
Design of intelligent humidification controller based on 51 single chip microcomputer
Meeting OA project seating function and submission function
Re understand the life world and ourselves
Several search terms
Abstract classes and interfaces (sorting out some knowledge points)
08_ Event modifier
Complete backpack and 01 Backpack
Meeting OA my meeting
Upload files to OSS file server