题意:
有
n
n
n个人,每个人都有一个能力值
b
i
b_i
bi以及他会的技能
a
i
a_i
ai,当他会第
x
x
x个技能的时候,
a
i
a_i
ai的第
x
x
x位是
1
1
1。定义当
x
x
x不会某个技能但是
y
y
y会的时候,
y
y
y就认为比
x
x
x好。一些人能够组成一个团队当且仅当团队中不存在一个人认为比所有人都好且团队中至少两个人。
求能组成的团队中能力值和最大的。
n
≤
7000
n\le7000
n≤7000
思路:
考虑如果两个人会的技能相同,那么这两个人一定可以在一个团队中。
考虑一个人
a
a
a会的技能是另一个人
b
b
b会的技能的子集,这个时候也可以将
a
a
a放入
b
b
b的集合中,前提是与
b
b
b会的技能相同的人
≥
2
\ge2
≥2。
考虑两个人会的技能不相同的时候,首先他们两个一定是相互认为都比对方好的,那么需要有能让他们各自都不认为比他好的,也就只有跟他们技能相同的人了,所以最终的答案一定是若干个技能完全相同的人数
≥
2
\ge2
≥2的人以及他们的子集之和。
// Problem: D. Marcin and Training Camp
// Contest: Codeforces - Codeforces Round #588 (Div. 2)
// URL: https://codeforces.com/contest/1230/problem/D
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
LL a[N],b[N],ans;
vector<LL>v;
map<LL,LL>sum,mp,st;
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) {
cin>>b[i];
if(!mp.count(a[i])) v.pb(a[i]);
sum[a[i]]+=b[i];
mp[a[i]]++;
}
for(auto x:v) {
if(st.count(x)||mp[x]<2) continue;
st[x]=1; ans+=sum[x];
for(auto y:v) {
if(x==y) continue;
if(st.count(y)) continue;
if((x|y)==x) st[y]=1,ans+=sum[y];
}
}
printf("%lld\n",ans);
return 0;
}
/*
*/