【题目链接】
【思路要点】
- 补档博客,无题解。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 5005 #define MAXLOG 60 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int n, home[MAXN], value[MAXN]; long long num[MAXN], basis[MAXN]; bool cmp(int x, int y) { return value[x] > value[y]; } int main() { read(n); for (int i = 1; i <= n; i++) { read(num[i]), read(value[i]); home[i] = i; } sort(home + 1, home + n + 1, cmp); int ans = 0; for (int i = 1; i <= n; i++) { long long tmp = num[home[i]]; bool succeeded = true; for (int j = 60; j >= 0; j--) { long long bit = 1ll << j; if (tmp & bit) { if (basis[j] == 0) { basis[j] = tmp; break; } else { tmp ^= basis[j]; if (tmp == 0) { succeeded = false; break; } } } } if (succeeded) ans += value[home[i]]; } cout << ans << endl; return 0; }