Codeforces Round 1066 (Div. 1 + Div. 2)
H
Keygen 3
Codeforces
3300
原题
← GI →
翻译中…
翻译中…

A permutation$^{\text{∗}}$ of length $n$ is called valid if it has both of the following properties:

翻译中…
  • It is bitonic$^{\dagger}$;
  • Exactly $m$ of its subsets are cycles$^{\ddagger}$.
翻译中…

Let $k$ denote the number of permutations satisfying the above condition. Your task is to find and print $\min(k, 2000)$ examples of such permutations.

翻译中…

$^{\dagger}$ A permutation $p_1, p_2, \ldots, p_n$ is bitonic if there exists an index $i$ ($1 \leq i \leq n$) such that

翻译中…
  • $p_{j-1} \leq p_j$ for $2 \leq j \leq i$;
  • $p_j \geq p_{j+1}$ for $i \leq j \leq n-1$.
翻译中…

$^{\ddagger}$ A subset $C \subseteq \{ 1, 2, \ldots, n \}$ is a cycle if it satisfies the following conditions:

翻译中…
  • $C$ is non-empty;
  • if $x \in C$, then $p_x \in C$;
  • $C$ is minimal, i.e., there does not exist a cycle $C'$ such that $C' \subset C$.
翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

The input consists of a single line containing two integers $n$, $m$ ($1 \le m \leq n \le 100$) — the length of the permutations and the target number of cycles.

翻译中…

Output

翻译中…

In the first line, print a single integer $r$: the number of permutations you are going to print. Note that $r$ must be $\min(k, 2000)$ as defined in the statement.

翻译中…

Then, print $r$ lines. Each line must contain a bitonic permutation of length $n$, with $m$ cycles.

翻译中…

Note

翻译中…

In the example, there are $9$ valid permutations (i.e., bitonic permutations of length $6$, with $3$ cycles). For example, $[3, 5, 6, 4, 2, 1]$ is bitonic (in the above definition, $i = 3$), and it has $3$ cycles: $\{1, 3, 6\}$, $\{2, 5\}$, $\{4\}$. So you have to print $r = \min(9, 2000) = 9$ such permutations.

翻译中…

样例

Input #1
6 3
Output #1
9
1 4 5 6 3 2
6 5 4 3 2 1
1 2 4 5 6 3
1 2 5 6 4 3
1 3 4 6 5 2
1 5 6 4 3 2
3 5 6 4 2 1
1 3 6 5 4 2
2 6 5 4 3 1
InputCopy OutputCopy
题目信息
题号
2157H
时间限制
4 s
内存限制
256 MB
标签
暴力
组合数学
构造
DFS 及类似
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。