F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

permutation 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1608    Accepted Submission(s): 733


Problem Description
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$.
 

Input
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!)$
 

Output
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.
 

Sample Input
7 3 1 3 2 3 3 3 4 3 5 3 6 20 10000
 

Sample Output
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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 11:46:21, Gzip enabled