QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#12631. 寻找美味

Statistics

Fouad 去了一家餐厅,在阅读菜单时,他发现菜单中包含了一项关于每道菜的有趣信息。这项信息就是每道菜所包含的口味。

菜单包含 $N$ 道菜,每道菜由一个整数 $A_i$ 表示,其中 $A_i$ 二进制表示中的第 $j$ 位代表这道菜是否包含第 $j$ 种口味(1 表示吃这道菜能感受到第 $j$ 种口味,0 表示不能)。

如果你吃了一些菜,只要其中任意一道菜的第 $j$ 位为 1,你就能感受到第 $j$ 种口味。换句话说,吃下 $A_i$ 和 $A_j$ 两道菜所包含的口味,等同于数字 $A_i \odot A_j$ 所包含的口味,其中 $\odot$ 是按位或(bitwise OR)运算。

Fouad 希望尽可能多地品尝菜肴以获得最大的享受,但他不能吃超过 $K$ 道菜(因为他有严格的饮食限制)。由于并非所有口味都相同,他请求你帮助他选择一个最多包含 $K$ 道菜的子集,使得代表整体食物口味的数字尽可能大(即所选菜肴按位或的结果尽可能大)。

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。

每个测试用例的第一行包含两个空格分隔的整数 $N, K$(其中 $20 \le K \le N \le 10^5$)。

每个测试用例的第二行包含 $N$ 个空格分隔的整数 $A_1, \dots, A_N$(其中对于所有 $i$,有 $0 \le A_i \le 10^6$)。

输出格式

对于每个测试用例,输出一行,包含一个整数 $X$,表示 Fouad 通过吃最多 $K$ 道菜所能感受到的口味的最大值。如果 Fouad 所吃的菜肴子集包含第 $i$ 种口味,则 $X$ 的第 $i$ 位必须为 1,否则第 $i$ 位必须为 0。

样例

输入 1

1
25 25
1 32 45 53 12 45 32 47 53 61 51 50 2 43
47 1 2 3 4 5 6 7 8 9 10

输出 1

63

说明

在样例中,他可以吃掉所有的菜,因此结果是所有给定数字的按位或结果。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.