CF513B2.Permutations
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:

Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).
给你一个数字 1,2,…,n 的排列 p。定义 f(p) 为如下和式:

在所有使 f(p) 取得最大可能值的长度为 n 的排列构成的集合中,找出字典序第 m 小的排列。
输入格式
The single line of input contains two integers n and m (1 ≤ m ≤ cnt__n), where cnt__n is the number of permutations of length n with maximum possible value of f(p).
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem B1 (3 points), the constraint 1 ≤ n ≤ 8 will hold.
- In subproblem B2 (4 points), the constraint 1 ≤ n ≤ 50 will hold.
输入仅包含一行,其中有两个整数 n 和 m(1 ≤ m ≤ cntn),其中 cntn 表示长度为 n 且 f(p) 取最大可能值的排列个数。
本题包含两个子问题。两个子问题对输入的约束不同。正确提交某个子问题可获得相应分数。子问题描述如下:
- 子问题 B1(3 分):满足约束 1 ≤ n ≤ 8;
- 子问题 B2(4 分):满足约束 1 ≤ n ≤ 50。
输出格式
Output n number forming the required permutation.
输出构成所需排列的 n 个数。
输入输出样例
输入#1
2 2
输出#1
2 1
输入#2
3 2
输出#2
1 3 2
说明/提示
In the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.
在第一个例子中,数字 {1, 2} 的两种排列均使 f(p) 取得最大可能值 4。其中,(2, 1) 在字典序中排第二。
输入解题思路,AI测评打分。不知道怎么写?