RT
考场上没时间了,写了个O(na^2)的
然后luogu 50pts
云斗 65pts
================ 然后把unordered_map换成gp_hash_table可以得到:
luogu : 65pts 云斗 : 75pts
不知道CCF的数据具体能放过我多少分
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200005;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T --){
int n;
cin>>n;
unordered_map<int,int> ans;
ans[0] = 0;
for(int i = 1;i <= n;++ i){
int a;
cin>>a;
unordered_map<int,int> tmp;
for(auto p : ans){
int s = p.first;
int w = p.second;
int x = s & ((1 << 22) - 1);
s >>= 22;
int y = s & ((1 << 22) - 1);
tmp[(a << 22) | y] = max(tmp[(a << 22) | y],w + (a == x ? a : 0));
tmp[x | (a << 22)] = max(tmp[x | (a << 22)],w + (a == y ? a : 0));
}
ans = tmp;
}
int sum = 0;
for(auto x : ans) sum = max(sum,x.second);
cout<<sum<<"\n";
}
return 0;
}