5337: 排列

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

B1.排列
每次测试的时间限制
2 秒
每个测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出
给你一个排列 p 为数字 1,2,...,n。让我们将 fp) 定义为以下总和:

在具有最大可能值 fp 的排列集中找到长度为 n 的字典顺序第 m 个排列。

输入
单行输入包含两个整数 n 和 m (1≤m≤cnt n),其中 cnt n 是长度为 n 的排列数,最大可能值为 fp)。
该问题由两个子问题组成。子问题对输入有不同的约束。正确提交子问题将获得一些分数。子问题的描述如下。

  • 在子问题 B1(3 个点)中,约束 1≤n≤8 将成立。
  • 在子问题 B2(4 个点)中,约束 1≤n≤50 将成立。
输出
输出 n 个数字,形成所需的排列。
例子
输入
2 2
输出
2 1 
输入
3 2
输出
1 3 2 
注意
在第一个示例中,数字 {1, 2} 的两个排列都产生最大可能的 fp),等于 4。其中,(2,1)按词典顺序排名第二。
B1. Permutations
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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).

Input
The single line of input contains two integers n and m (1≤mcntn), where cntn 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.
Output
Output n number forming the required permutation.
Examples
Input
2 2
Output
2 1 
Input
3 2
Output
1 3 2 
Note
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.

输入样例 复制


输出样例 复制