CF1365E Maximum Subsequence Value
题目描述
给出一个长度为 $n$ 的数列 $a$,你需要选出一个子序列,使其价值最大,输出最大的价值。
对于一个长度为 $k$ 的子序列,若在这个子序列中有不少于 $\max(1,k-2)$ 个数的二进制位 $i$ 上是 $1$,则其价值增加 $2^i$。
输入格式
第一行有一个正整数 $n$,表示数列长度。
之后一行 $n$ 个整数,表示数列 $a$。
保证 $1\le n\le500$,$1\le a_i\le10^{18}$。
输出格式
输出最大的价值。
说明/提示
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 $ 2^0 + 2^1 $ (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 $ .