当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6628:permutation 1

题目描述
A sequence of length $n$ is called a permutation if and only if it's composed of the first $n$ positive integers and each number appears exactly once.

Here we define the "difference sequence" of a permutation $p_1, p_2, \ldots, p_n$ as $p_2 - p_1, p_3 - p_2, \ldots, p_n - p_{n-1}$. In other words, the length of the difference sequence is $n-1$ and the $i$-th term is $p_{i+1}-p_i$

Now, you are given two integers $N, K$. Please find the permutation with length $N$ such that the difference sequence of which is the $K$-th lexicographically smallest among all difference sequences of all permutations of length $N$.
输入解释
The first line contains one integer $T$ indicating that there are $T$ tests.

Each test consists of two integers $N, K$ in a single line.

* $1 \le T \le 40$

* $2 \le N \le 20$

* $1 \le K \le \min(10^4,N!)$
输出解释
For each test, please output $N$ integers in a single line. Those $N$ integers represent a permutation of $1$ to $N$, and its difference sequence is the $K$-th lexicographically smallest.
输入样例
7
3 1
3 2
3 3
3 4
3 5
3 6
20 10000
输出样例
3 1 2
3 2 1
2 1 3
2 3 1
1 2 3
1 3 2
20 1 2 3 4 5 6 7 8 9 10 11 13 19 18 14 16 15 17 12
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6628

最后修改于 2020-10-25T23:32:58+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)