題目
題意:
給你一個序列,對於每一個都對應着一個二進制,我們可以選擇個數字,我們需要找出這些數字中每個位子至少有個的位子,然後化成,如何選擇這些數字使其最大,問最大是多少。
思路:
我們可以分析一下不同的情況:
- 當的時候,那答案肯定就是了。
- 當的時候,那麼每個位子上只要有一個至少一個存在就行了,那麼也可以直接。
- 當的時候,道理同上
- 當的時候,那麼現在每個位子上所需要的就會越來越多,試想一下,雖然每次都可以多選擇一個數字,但是每個位子所需要的也要越來越多,那麼如果這個數字能夠增加的話,那麼爲什麼我們在選擇個數字的不選擇這個數字,因爲如果要增加的,那麼就是這個數能覆蓋前面一個數字的基礎上纔可以增加,但是這樣的話,可以在剛開始就選擇這個數,所以最大的時候,選擇。
#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;
}