QOJ.ac

QOJ

時間限制: 8.0 s 記憶體限制: 1024 MB 總分: 100

#8529. 排列的平衡

统计

对于一个 $1$ 到 $n$ 的排列 $p$,其平衡度(balance)定义为 $\sum_{i=1}^n |p_i - i|$。你的任务是找到长度为 $n$ 且平衡度等于 $b$ 的所有排列中,字典序第 $k$ 小的排列。

输入格式

输入包含一行,包含三个整数 $n, b$ 和 $k$ ($1 \le n \le 30; 0 \le b; 1 \le k$),含义如题目描述所述。

保证存在至少 $k$ 个长度为 $n$ 且平衡度为 $b$ 的排列。

注意参数 $k$ 的值可能无法用 64 位数据类型存储。在 C++ 中,我们建议使用 __int128 类型来存储它。

输出格式

输出应包含 $n$ 个整数,占一行,即所求的排列。

样例

样例输入 1

6 6 6

样例输出 1

1 2 6 3 4 5

样例输入 2

30 300 3030303030303030303030

样例输出 2

1 2 3 4 9 23 20 28 24 16 21 17 27 29 8 26 25 30 19 18 22 12 7 13 6 10 5 15 14 11

说明

考虑第一个样例。长度为 6 且平衡度为 6 的排列共有 46 个。其中字典序第 6 小的排列是 $[1, 2, 6, 3, 4, 5]$。

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.