CF2179D.Blackslex and Penguin Civilization

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Penguins are civilized creatures that communicate using permutations. Blackslex, as a penguin researcher, must study their means of communication.

For a given integer nn, consider permutations∗^{\text{∗}} pp of the array [0,1,…,2n−1][0, 1, \ldots, 2^n - 1]. Define $$S(p) \;=\; \sum_{i=0}{2n-1} \operatorname{popcount}\!\bigl(p_0 \mathbin{\&} p_1 \mathbin{\&} \cdots \mathbin{\&} p_i\bigr),$$ where popcount⁡(z)\operatorname{popcount}(z) is the number of 11-bits in the binary representation of zz (for instance, popcount⁡(5)=2\operatorname{popcount}(5) = 2 because 5=10125 = 101_2 has two 11-bits in the binary representation), and &\& denotes the bitwise AND operation. .

A permutation is considered sacred if it maximizes S(p)S(p). Find the lexicographically minimal†^{\text{†}} sacred permutation.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

†^{\text{†}}An array aa is lexicographically smaller than an array bb of the same size if and only if the following holds:

  • in the first position where aa and bb differ, the array aa has a smaller element than the corresponding element in bb.

企鹅是文明的生物,它们使用排列进行交流。作为企鹅研究员,布莱克斯莱克斯必须研究它们的交流方式。

对于给定的整数 nn,考虑数组 [0,1,…,2n−1][0, 1, \ldots, 2^n - 1] 的所有排列∗^{\text{∗}} pp。定义

S(p)  =  ∑i=02n−1popcount⁡ ⁣(p0&p1&⋯&pi),S(p) \;=\; \sum_{i=0}^{2^n-1} \operatorname{popcount}\!\bigl(p_0 \mathbin{\&} p_1 \mathbin{\&} \cdots \mathbin{\&} p_i\bigr),

其中 popcount⁡(z)\operatorname{popcount}(z) 表示 zz 的二进制表示中 11 的个数(例如,popcount⁡(5)=2\operatorname{popcount}(5) = 2,因为 5=10125 = 101_2 的二进制表示中有两个 11),而 &\& 表示按位与运算。

若一个排列使得 S(p)S(p) 达到最大值,则称其为“神圣排列”。请找出字典序最小†^{\text{†}}的神圣排列。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

†^{\text{†}} 对于两个长度相同的数组 aa 和 bb,当且仅当满足以下条件时,称 aa 的字典序小于 bb:

  • 在 aa 与 bb 第一次出现不同元素的位置上,aa 中的对应元素严格小于 bb 中的对应元素。

输入格式

The first line contains a single integer tt (1≤t≤161 \le t \le 16) — the number of test cases.

Each test case contains a single integer nn (1≤n≤161 \le n \le 16).

It is guaranteed that the sum of 2n2^n over all test cases does not exceed 2162^{16}.

第一行包含一个整数 tt(1≤t≤161 \le t \le 16)—— 测试用例的数量。

每个测试用例包含一个整数 nn(1≤n≤161 \le n \le 16)。

保证所有测试用例的 2n2^n 之和不超过 2162^{16}。

输出格式

For each test case, output 2n2^n integers p0,p1,…,p2n−1p_0, p_1, \ldots, p_{2^n-1} — the required permutation.

对于每个测试用例,输出 2n2^n 个整数 p0,p1,…,p2n−1p_0, p_1, \ldots, p_{2^n-1} —— 所需的排列。

输入输出样例

  • 输入#1

    2
    1
    2

    输出#1

    1 0 
    3 1 0 2

说明/提示

For the first test case, there are two possible permutations.

  • p=[0,1]p = [0, 1], S(p)=0S(p) = 0
  • p=[1,0]p = [1, 0], S(p)=1S(p) = 1

For the second test case, S([3,1,0,2])=3S([3, 1, 0, 2]) = 3 is sacred. There are other permutations pp that are sacred, such as p=[3,2,0,1]p = [3, 2, 0, 1], but those are not lexicographically minimal.

对于第一个测试用例,存在两种可能的排列:

  • p=[0,1]p = [0, 1],S(p)=0S(p) = 0
  • p=[1,0]p = [1, 0],S(p)=1S(p) = 1

对于第二个测试用例,S([3,1,0,2])=3S([3, 1, 0, 2]) = 3 是神圣的。存在其他神圣的排列 pp,例如 p=[3,2,0,1]p = [3, 2, 0, 1],但这些排列并非字典序最小的。

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

首页