题解:P16964 [SCCPC 2026] 最大权独立集问题
Shiono_Kaze · · 题解
省赛的签到题
解析
两点之间有边当且仅当它们二进制表示中
下面是对完全二分图的一个粗略证明。
证明:
对于任意非负整数
那么边
这意味着
于是,我们可以将所有点按照
因此,图
AC Code
# include <bits/stdc++.h>
# define int long long
using namespace std;
void solve(void){
int n;
cin >> n;
vector <int> arr(n);
for (auto &num : arr) cin >> num;
int odd = 0,even = 0;
for (const auto &num : arr){
if (__builtin_popcount(num) & 1) odd += num;
else even += num;
}
cout << max(odd,even) << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}