Bridge Club solution codeforces

For Solution
Click Here!
There are currently nn hot topics numbered from 00 to n−1n−1 at your local bridge club and 2n2n players numbered from 00 to 2n−12n−1. Each player holds a different set of views on those nn topics, more specifically, the iith player holds a positive view on the jjth topic if i & 2j>0i & 2j>0, and a negative view otherwise. Here && denotes the bitwise AND operation.
You are going to organize a bridge tournament capable of accommodating at most kk pairs of players (bridge is played in teams of two people). You can select teams arbitrarily, but there is one catch: two players cannot be in the same pair if they disagree on 22 or more of those nn topics, as they would argue too much during the play.
You know that the iith player will pay you aiai dollars if they play in this tournament. Compute the maximum amount of money that you can earn if you pair the players in your club optimally.
The first line contains two integers nn, kk (1≤n≤201≤n≤20, 1≤k≤2001≤k≤200) — the number of hot topics and the number of pairs of players that your tournament can accommodate.
The second line contains 2n2n integers a0,a1,…,a2n−1a0,a1,…,a2n−1 (0≤ai≤1060≤ai≤106) — the amounts of money that the players will pay to play in the tournament.
Print one integer: the maximum amount of money that you can earn if you pair the players in your club optimally under the above conditions.
input
3 1 8 3 5 7 1 10 3 2
output Bridge Club solution codeforces
13
input
2 3 7 4 5 7
output
23
input
3 2 1 9 1 5 7 8 1 1
output
29
In the first example, the best we can do is to pair together the 00th player and the 22nd player resulting in earnings of 8+5=138+5=13 dollars. Although pairing the 00th player with the 55th player would give us 8+10=188+10=18 dollars, we cannot do this because those two players disagree on 22 of the 33 hot topics.
In the second example, we can pair the 00th player with the 11st player and pair the 22nd player with the 33rd player resulting in earnings of 7+4+5+7=237+4+5+7=23 dollars.

For Solution
Click Here!