Marcin and Training Camp
https://codeforces.com/contest/1230/problem/D
思路:找到两个相同的肯定要,这样就满足情况,然后把所有包含关系的都要。如果x|y=x,那么x包含y。
#include<cstring> #include<algorithm> #include<vector> #include<map> #include<queue> #include<cstdio> #include<stack> #include<cmath> #include<iostream> #include<set> #define ll long long #define lowbit(x) x&(-x) using namespace std; struct point { ll x; ll y; }a[10000]; map<ll,int> mp; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i].x); mp[a[i].x]++; } for(int i=1;i<=n;i++) scanf("%lld",&a[i].y); ll ans=0; set<int> ss; for(map<ll,int>::iterator t=mp.begin();t!=mp.end();t++) { if(t->second>=2) { for(int i=1;i<=n;i++) { if((t->first|a[i].x)==t->first) ss.insert(i); } } } for(set<int>::iterator t=ss.begin();t!=ss.end();t++) { //printf("%d\n",*t); int o= (*t); ans+=a[o].y; } printf("%lld\n",ans); }