Problem Statement
Given is a number sequence AA of length NN.
Let us divide this sequence into one or more non-empty contiguous intervals.
Then, for each of these intervals, let us compute the bitwise OROR of the numbers in it.
Find the minimum possible value of the bitwise XORXOR of the values obtained in this way.
Constraints
- 1≤N≤201≤N≤20
- 0≤Ai<2300≤Ai<230
- All values in input are integers.
Sample Input 1
3
1 5 7
Sample Output 1
2
If we divide [1,5,7][1,5,7] into [1,5][1,5] and [7][7], their bitwise ORORs are 55 and 77, whose XORXOR is 22.
It is impossible to get a smaller result, so we print 22.
数据范围 20
所以是个暴搜题,枚举n-1个位置的插条,插和不插
1 暴搜策略dfs
2 2进制枚举
思路:
枚举每一位tmp = tmp | a[i] 遇到1,即插了一个板子的时候 加入结果ans ^= tmp
边界条件的考虑: 最后一位时要加入结果
坑: INF 会被卡掉0x3f3f3f3f不够大导致的,把INF改成INF+INF就过了。
code:
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 100003
#define mod 100000
#define pb push_back
#define x first
#define y second
#define ull unsigned long long
#define ll long long
using namespace std;
int a[N];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
cin >> n;
for(int i = 0;i < n;i++)
{
cin >> a[i];
}
int mn = INF + INF ;
for(int i = 0;i < (1 << (n - 1));i++)
{
int tmp = 0;
int res = 0;
for(int j = 0;j <= n;j++)
{
if(j < n)
tmp |= a[j];
if(j == n || ((i >> j) & 1))
{
res ^= tmp;
tmp = 0;
}
}
mn = min(res,mn);
}
cout << mn << endl;
return 0;
}