CF1572D.Bridge Club

省选/NOI-

通过率:0%

时间限制:2.50s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are currently nn hot topics numbered from 00 to n−1n-1 at your local bridge club and 2n2^n players numbered from 00 to 2n−12^n-1. Each player holds a different set of views on those nn topics, more specifically, the ii-th player holds a positive view on the jj-th topic if i & 2j>0i\ \&\ 2^j \gt 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 while each player is in at most one team, 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 ii-th player will pay you aia_i 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.

目前,你们当地的桥牌俱乐部有 nn 个热门话题,编号从 00 到 n−1n-1;同时有 2n2^n 名玩家,编号从 00 到 2n−12^n-1。每位玩家对这 nn 个话题持有不同的观点:具体而言,第 ii 位玩家对第 jj 个话题持正面观点当且仅当 i & 2j>0i\ \&\ 2^j \gt 0,否则持负面观点。此处 &\& 表示按位与运算。

你将组织一场桥牌锦标赛,最多可容纳 kk 对选手(桥牌以两人一队的形式进行)。你可以任意选择组队方式,但每位玩家至多只能属于一个队伍;不过有一个限制条件:若两名玩家在上述 nn 个话题中至少有 22 个观点不一致,则他们不能组成一对,否则他们在比赛过程中会因争执过多而影响发挥。

已知第 ii 位玩家若参加本次锦标赛,将向你支付 aia_i 美元。请计算:若你以最优方式为俱乐部中的玩家组队,最多能获得多少美元收入。

输入格式

The first line contains two integers nn, kk (1≤n≤201 \le n \le 20, 1≤k≤2001 \le k \le 200) — the number of hot topics and the number of pairs of players that your tournament can accommodate.

The second line contains 2n2^n integers a0,a1,…,a2n−1a_0, a_1, \dots, a_{2^n-1} (0≤ai≤1060 \le a_i \le 10^6) — the amounts of money that the players will pay to play in the tournament.

第一行包含两个整数 nn、kk(1≤n≤201 \le n \le 20,1≤k≤2001 \le k \le 200)—— 分别表示热门话题的数量以及你的锦标赛所能容纳的玩家对数。

第二行包含 2n2^n 个整数 a0,a1,…,a2n−1a_0, a_1, \dots, a_{2^n-1}(0≤ai≤1060 \le a_i \le 10^6)—— 表示各玩家为参加锦标赛所支付的金额。

输出格式

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.

输出一个整数:在上述条件下,通过最优地配对俱乐部中的选手,你能获得的最大金额。

输入输出样例

  • 输入#1

    3 1
    8 3 5 7 1 10 3 2

    输出#1

    13
  • 输入#2

    2 3
    7 4 5 7

    输出#2

    23
  • 输入#3

    3 2
    1 9 1 5 7 8 1 1

    输出#3

    29

说明/提示

In the first example, the best we can do is to pair together the 00-th player and the 22-nd player resulting in earnings of 8+5=138 + 5 = 13 dollars. Although pairing the 00-th player with the 55-th 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 00-th player with the 11-st player and pair the 22-nd player with the 33-rd player resulting in earnings of 7+4+5+7=237 + 4 + 5 + 7 = 23 dollars.

在第一个例子中,我们能做的最优选择是将第 00 位玩家与第 22 位玩家配对,从而获得 8+5=138 + 5 = 13 美元的收益。尽管将第 00 位玩家与第 55 位玩家配对可带来 8+10=188 + 10 = 18 美元的收益,但这是不允许的,因为这两位玩家在 33 个热门话题中有 22 个持不同意见。

在第二个例子中,我们可以将第 00 位玩家与第 11 位玩家配对,并将第 22 位玩家与第 33 位玩家配对,从而获得 7+4+5+7=237 + 4 + 5 + 7 = 23 美元的收益。

输入解题思路,AI测评打分。不知道怎么写?

首页