#P16964. [SCCPC 2026] 最大权独立集问题
[SCCPC 2026] 最大权独立集问题
Problem Description
Given vertices, each vertex has an integer weight .
Define that there is an undirected edge between vertices and if and only if, in the binary representation of (where denotes bitwise XOR), the number of bits is odd.
Please find the maximum weight independent set of this graph. That is, choose a set of vertices such that there is no edge between any two vertices in the set, and the sum of weights of the chosen vertices is as large as possible. The weight of the empty set is defined as . You only need to output this maximum total weight.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer (), which denotes the number of test cases.
For each test case:
The first line contains a positive integer (), which denotes the number of vertices.
The second line contains positive integers (), which denote the weights of the vertices.
It is guaranteed that .
Output Format
For each test case, output one integer per line, representing the maximum total weight of an independent set.
3
5
3 5 15 1 2
3
6 7 11
4
1 2 4 8
23
18
15
Hint
Translated by ChatGPT 5