题目
题意:
给你一个序列,对于每一个都对应着一个二进制,我们可以选择个数字,我们需要找出这些数字中每个位子至少有个的位子,然后化成,如何选择这些数字使其最大,问最大是多少。
思路:
我们可以分析一下不同的情况:
- 当的时候,那答案肯定就是了。
- 当的时候,那么每个位子上只要有一个至少一个存在就行了,那么也可以直接。
- 当的时候,道理同上
- 当的时候,那么现在每个位子上所需要的就会越来越多,试想一下,虽然每次都可以多选择一个数字,但是每个位子所需要的也要越来越多,那么如果这个数字能够增加的话,那么为什么我们在选择个数字的不选择这个数字,因为如果要增加的,那么就是这个数能覆盖前面一个数字的基础上才可以增加,但是这样的话,可以在刚开始就选择这个数,所以最大的时候,选择。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
const int maxn = 510;
ll a[maxn] = {0};
int main() {
ll n; read(n); for (int i = 1; i <= n; i++) read(a[i]);
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) ans = max(ans, a[i] | a[j] | a[k]);
}
}
outl(ans);
return 0;
}