102632: [AtCoder]ABC263 C - Monotonically Increasing

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

Print all strictly increasing integer sequences of length $N$ where all elements are between $1$ and $M$ (inclusive), in lexicographically ascending order.

Notes

For two integer sequences of the same length $A_1,A_2,\dots,A_N$ and $B_1,B_2,\dots,B_N$, $A$ is said to be lexicographically earlier than $B$ if and only if:

  • there is an integer $i$ $(1 \le i \le N)$ such that $A_j=B_j$ for all integers $j$ satisfying $1 \le j < i$, and $A_i < B_i$.

An integer sequence $A_1,A_2,\dots,A_N$ is said to be strictly increasing if and only if:

  • $A_i < A_{i+1}$ for all integers $i$ $(1 \le i \le N-1)$.

Constraints

  • $1 \le N \le M \le 10$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$

Output

Print the sought sequences in lexicographically ascending order, each in its own line (see Sample Outputs).


Sample Input 1

2 3

Sample Output 1

1 2 
1 3 
2 3 

The sought sequences are $(1,2),(1,3),(2,3)$, which should be printed in lexicographically ascending order.


Sample Input 2

3 5

Sample Output 2

1 2 3 
1 2 4 
1 2 5 
1 3 4 
1 3 5 
1 4 5 
2 3 4 
2 3 5 
2 4 5 
3 4 5 

Input

题意翻译

打印所有长度为 $N$ 的严格递增序列,所有元素在 $1 $ 到 $M$ 之间。按照字典序升序输出。

Output

分数:300分

问题描述

按照字典序递增顺序打印长度为$N$的所有严格递增整数序列,其中所有元素都在$1$和$M$之间(包括$1$和$M$)。

注意

对于两个相同长度的整数序列$A_1,A_2,\dots,A_N$和$B_1,B_2,\dots,B_N$,如果满足以下条件,则称$A$比$B$字典序更早:

  • 存在整数$i$ $(1 \le i \le N)$,使得对于所有满足$1 \le j < i$的整数$j$,有$A_j=B_j$,并且$A_i < B_i$。

如果满足以下条件,则称整数序列$A_1,A_2,\dots,A_N$严格递增:

  • 对于所有整数$i$ $(1 \le i \le N-1)$,有$A_i < A_{i+1}$。

约束

  • $1 \le N \le M \le 10$
  • 输入中的所有值都是整数。

输入

输入通过标准输入给出以下格式:

$N$ $M$

输出

按照字典序递增顺序打印目标序列,每个序列单独一行(参见样例输出)。


样例输入1

2 3

样例输出1

1 2 
1 3 
2 3 

目标序列是$(1,2),(1,3),(2,3)$,需要按照字典序递增顺序打印。


样例输入2

3 5

样例输出2

1 2 3 
1 2 4 
1 2 5 
1 3 4 
1 3 5 
1 4 5 
2 3 4 
2 3 5 
2 4 5 
3 4 5 

加入题单

算法标签: