题目
题目大意:
每个人有一个懂得算法值
a
i
a_i
ai,能力值
b
i
b_i
bi,当一个人比另一个人优秀当且仅当这个人懂得算法值得二进制数中某一位为
1
1
1的值在另一个人对应的位上不为
1
1
1。我们要找到一群人(
2
≤
n
2 \leq n
2≤n),这一群人要满足,每一个都不必其他所有的人都优秀,求合法的人群的能力值的最大值。
题解
- 显然如果有能力值重复的人,那么我们便可以找到在二进制下能力值的子集。 所有能力值在子集范围内的便可直接累加答案。
c o d e code code
#include <bits/stdc++.h>
using namespace std;
const int maxn = 7100;
typedef long long LL;
int n;
struct node {
LL x, y;
} a[maxn];
map<LL, int> mp;
int main() {
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);
set<int> st;
for (map<LL, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
int y = it->second;
LL x = it->first;
if (y > 1) {
for (int i = 1; i <= n; ++i) {
if ((a[i].x | x) == x) {
st.insert(i);
}
}
}
}
LL ans = 0;
for (set<int>::iterator it = st.begin(); it != st.end(); ++it) {
ans += a[*it].y;
}
printf("%lld\n", ans);
return 0;
}