CF1365E.Maximum Subsequence Value
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers.
The value of a non-empty subsequence of k elements of a is defined as ∑2i over all integers i≥0 such that at least max(1,k−2) elements of the subsequence have the i-th bit set in their binary representation (value x has the i-th bit set in its binary representation if ⌊2ix⌋mod2 is equal to 1).
Recall that b is a subsequence of a, if b can be obtained by deleting some(possibly zero) elements from a.
Help Ashish find the maximum value he can get by choosing some subsequence of a.
里迪曼向阿西什发起挑战,要求他找出一个由 n 个正整数组成的数组 a 的最大值子序列。
一个非空子序列(含 k 个元素)的值定义为:对所有满足条件的整数 i≥0,求和 ∑2i;其中“条件”是指:该子序列中至少有 max(1,k−2) 个元素在二进制表示中第 i 位为 1(即,若某数 x 满足 ⌊2ix⌋mod2=1,则称其二进制表示中第 i 位被置位)。
注意:若数组 b 可通过从 a 中删除若干(可能为零)元素得到,则称 b 是 a 的一个子序列。
请帮助阿西什找出:通过选择 a 的某个子序列所能获得的最大值。
输入格式
The first line of the input consists of a single integer n (1≤n≤500) — the size of a.
The next line consists of n space-separated integers — the elements of the array (1≤ai≤1018).
输入的第一行包含一个整数 n (1≤n≤500) —— 表示数组 a 的大小。
第二行包含 n 个以空格分隔的整数 —— 数组的元素 (1≤ai≤1018)。
输出格式
Print a single integer — the maximum value Ashish can get by choosing some subsequence of a.
输出一个整数——Ashish 通过选择数组 a 的某个子序列所能获得的最大值。
输入输出样例
输入#1
3 2 1 3
输出#1
3
输入#2
3 3 1 4
输出#2
7
输入#3
1 1
输出#3
1
输入#4
4 7 7 1 1
输出#4
7
说明/提示
For the first test case, Ashish can pick the subsequence 2,3 of size 2. The binary representation of 2 is 10 and that of 3 is 11. Since max(k−2,1) is equal to 1, the value of the subsequence is 20+21 (both 2 and 3 have 1-st bit set in their binary representation and 3 has 0-th bit set in its binary representation). Note that he could also pick the subsequence 3 or 2,1,3.
For the second test case, Ashish can pick the subsequence 3,4 with value 7.
For the third test case, Ashish can pick the subsequence 1 with value 1.
For the fourth test case, Ashish can pick the subsequence 7,7 with value 7.
对于第一个测试用例,Ashish 可以选择长度为 2 的子序列 {2,3}。2 的二进制表示为 10,3 的二进制表示为 11。由于 max(k−2,1) 等于 1,该子序列的值为 20+21(因为 2 和 3 的二进制表示中第 1 位均为 1,且 3 的二进制表示中第 0 位为 1)。注意,他也可以选择子序列 {3} 或 {2,1,3}。
对于第二个测试用例,Ashish 可以选择子序列 {3,4},其值为 7。
对于第三个测试用例,Ashish 可以选择子序列 {1},其值为 1。
对于第四个测试用例,Ashish 可以选择子序列 {7,7},其值为 7。
输入解题思路,AI测评打分。不知道怎么写?