#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <string>
// #include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int>a,pair<int,int>b) {
//第二位从小到大
if (a.second!=b.second) {
return a.second<b.second;
}
//第一位从大到小
else {
return a.first>b.first;
}
}
bool cmp1(int a,int b) {
if (a>b) {
return true;
}
else {
return false;
}
}
struct node {
int a;
int b;
int cha;
};
bool cmp2(node a,node b){
if (a.cha>b.cha) {
return true;
}
return false;
}
bool cmp3(string a,string b) {
if (a+b>b+a) {
return true;
}
return false;
}
int main() {
int t;
cin>>t;
while (t-->0) {
int n;
cin>>n;
int a[n+1];
a[0]=0;
for (int i=1;i<=n;i++) {
cin>>a[i];
}
for (int i=2;i<=n;i++) {
a[i]^=a[i-1];
}
vector<long long> dp(n+1,(long long)1e9+7);
dp[0]=0;
for (int i=1;i<=n;i++) {
for (int j=1;j<=i;j++) {
dp[i]=min(dp[i],(a[i]^a[j-1])+dp[j-1]);
}
}
cout<<dp[n]<<endl;
}
return 0;
}
全部评论
(1) 回帖