#ABC473D. 系数阶梯 / Coefficient Stair
系数阶梯 / Coefficient Stair
Problem Statement
Output all length- sequences consisting of non-negative integers that satisfy , in lexicographic order from smallest to largest.
Here, you will only receive inputs such that the number of sequences satisfying the condition is at most .
What is lexicographic order for sequences?
A sequence is said to be lexicographically smaller than a sequence if either 1. or 2. below holds. Here, and denote the lengths of and , respectively.
- and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$.
- There exists an integer such that both of the following hold.
- $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$
- is (numerically) smaller than .
Constraints
- The number of sequences satisfying the condition is at most .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the number of sequences of non-negative integers satisfying the condition; output them over lines. Each line should contain the elements of a sequence of non-negative integers satisfying the condition, in order, separated by spaces. For every sequence, all sequences outputed before it must be lexicographically smaller than it.
3 8
0 1 2
0 4 0
1 2 1
2 0 2
2 3 0
3 1 1
4 2 0
5 0 1
6 1 0
8 0 0
For example, for the sequence we have , so it satisfies the condition. There is no sequence satisfying the condition that is lexicographically smaller than this one, so output 0 1 2 on the first line.
Including , ten sequences satisfy the condition. Output these in lexicographic order from smallest to largest.
1 200000
200000
8 9
0 0 0 1 1 0 0 0
0 0 1 0 0 1 0 0
0 0 3 0 0 0 0 0
0 1 0 0 0 0 1 0
0 1 1 1 0 0 0 0
0 2 0 0 1 0 0 0
0 3 1 0 0 0 0 0
1 0 0 0 0 0 0 1
1 0 0 2 0 0 0 0
1 0 1 0 1 0 0 0
1 1 0 0 0 1 0 0
1 1 2 0 0 0 0 0
1 2 0 1 0 0 0 0
1 4 0 0 0 0 0 0
2 0 0 0 0 0 1 0
2 0 1 1 0 0 0 0
2 1 0 0 1 0 0 0
2 2 1 0 0 0 0 0
3 0 0 0 0 1 0 0
3 0 2 0 0 0 0 0
3 1 0 1 0 0 0 0
3 3 0 0 0 0 0 0
4 0 0 0 1 0 0 0
4 1 1 0 0 0 0 0
5 0 0 1 0 0 0 0
5 2 0 0 0 0 0 0
6 0 1 0 0 0 0 0
7 1 0 0 0 0 0 0
9 0 0 0 0 0 0 0
- Source: AtCoder ABC 473 D
相关
在下列比赛中: