这题的关键是如何分组。
想象一下在一个数组中每两个数组间存在一个间隙,我们可以枚举每个间隙中是否存在一个“隔板”,当存在时就代表重新开始一个区间。可采用二进制枚举。
一共有n-1个间隙,共2^(n-1)种情况。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e6 + 10;
const int M_MAX = 50000 + 10;
const int mod = 1e9 + 7;
const LL INF = 1e17;
const double eps = 1e-6;
// 2^20 = 2e6;
// 10! = 3e6;
int arr[2010];
void solve() {
LL res = INF;
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> arr[i];
for(int i = 0; i < 1 << (n - 1); i++) {
LL temp = 0, re = 0;
for(int j = 0; j < n; j++) {
temp |= arr[j];
if(j == n - 1 || 1 << j & i) {
re ^= temp;
temp = 0;
}
}
res = min(re, res);
}
cout << res << endl;
}
int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\in.txt", "r", stdin);
solve();
return 0;
}