AT_abc473_d.Coefficient Stair

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Output all length-NN sequences A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N) consisting of non-negative integers that satisfy ∑i=1Ni×Ai=K\displaystyle\sum _ {i=1} ^ Ni\times A _ i=K, 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 3×1053\times10 ^ 5.

What is lexicographic order for sequences?

A sequence S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) is said to be lexicographically smaller than a sequence T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}) if either 1. or 2. below holds. Here, ∣S∣|S| and ∣T∣|T| denote the lengths of SS and TT, respectively.

  1. ∣S∣<∣T∣|S| \lt |T| and (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}).
  2. There exists an integer 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace such that both of the following hold.
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
    • SiS_i is (numerically) smaller than TiT_i.

输出所有长度为 NN 的非负整数序列 A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N),满足 ∑i=1Ni×Ai=K\displaystyle\sum _ {i=1} ^ Ni\times A _ i=K,并按字典序从小到大排列。

本题保证输入数据满足:满足条件的序列总数不超过 3×1053\times10 ^ 5。

什么是序列的字典序?

序列 S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) 被称为字典序小于序列 T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}),当且仅当以下条件 1 或 2 成立。其中,∣S∣|S| 和 ∣T∣|T| 分别表示序列 SS 和 TT 的长度。

  1. ∣S∣<∣T∣|S| \lt |T|,且 (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})。
  2. 存在整数 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace,使得以下两个条件同时成立:
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1});
    • SiS_i(数值上)小于 TiT_i。

输入格式

The input is given from Standard Input in the following format:

NN KK

输入从标准输入中以如下格式给出:

NN KK

输出格式

Let qq be the number of sequences of non-negative integers satisfying the condition; output them over qq 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 outputted before it must be lexicographically smaller than it.

设 qq 为满足该条件的非负整数序列的个数;将这些序列按行输出,共 qq 行。每行应按顺序包含一个满足条件的非负整数序列的各元素,元素之间用空格分隔。对于任意一个序列,所有在它之前输出的序列都必须字典序小于它。

输入输出样例

  • 输入#1

    3 8

    输出#1

    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
  • 输入#2

    1 200000

    输出#2

    200000
  • 输入#3

    8 9

    输出#3

    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

说明/提示

Sample 1 Explanation:
For example, for the sequence (0,1,2)(0,1,2) we have 0×1+1×2+2×3=0+2+6=80\times1+1\times2+2\times3=0+2+6=8, 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 (0,1,2)(0,1,2), ten sequences satisfy the condition. Output these in lexicographic order from smallest to largest.

Constraints

  • 1≤N≤101\le N\le 10
  • 1≤K≤2×1051\le K\le 2\times10 ^ 5
  • The number of sequences satisfying the condition is at most 3×1053\times10 ^ 5.
  • All input values are integers.

样例 1 解释:
例如,对于序列 (0,1,2)(0,1,2),有 0×1+1×2+2×3=0+2+6=80\times1+1\times2+2\times3=0+2+6=8,因此它满足条件。不存在字典序比该序列更小且满足条件的序列,故第一行输出 0 1 2。

包括 (0,1,2)(0,1,2) 在内,共有十个序列满足条件。请将这些序列按字典序从小到大输出。

限制条件

  • 1≤N≤101\le N\le 10
  • 1≤K≤2×1051\le K\le 2\times10 ^ 5
  • 满足条件的序列个数至多为 3×1053\times10 ^ 5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页