#abc335b. B - Tetrahedral Number

B - Tetrahedral Number

Score : 150150 points

问题描述

给定一个整数 NN

按照升序字典序打印满足条件 x+y+zNx+y+z\leq N 的所有非负整数三元组 (x,y,z)(x, y, z)

非负整数三元组的字典序是什么?

如果以下任意条件成立,则称非负整数三元组 (x,y,z)(x, y, z) 在字典序上 小于 三元组 (x,y,z)(x', y', z')

  • x<xx < x'
  • x=xx=x'y<yy< y'
  • x=xx=x'y=yy=y'z<zz< z'.

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an integer NN.

Print all triples of non-negative integers (x,y,z)(x,y,z) such that x+y+zNx+y+z\leq N in ascending lexicographical order.

What is lexicographical order for non-negative integer triples?

A triple of non-negative integers (x,y,z)(x,y,z) is said to be lexicographically smaller than (x,y,z)(x',y',z') if and only if one of the following holds:

  • x<xx < x';
  • x=xx=x' and y<yy< y';
  • x=xx=x' and y=yy=y' and z<zz< z'.

Constraints

  • 0N210 \leq N \leq 21
  • NN is an integer.

Input

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

NN

Output

Print all triples of non-negative integers (x,y,z)(x,y,z) such that x+y+zNx+y+z\leq N in ascending lexicographical order, with x,y,zx,y,z separated by spaces, one triple per line.

Sample Input 1

3

Sample Output 1

0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 3 0
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 2 0
2 0 0
2 0 1
2 1 0
3 0 0

Sample Input 2

4

Sample Output 2

0 0 0
0 0 1
0 0 2
0 0 3
0 0 4
0 1 0
0 1 1
0 1 2
0 1 3
0 2 0
0 2 1
0 2 2
0 3 0
0 3 1
0 4 0
1 0 0
1 0 1
1 0 2
1 0 3
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 3 0
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 2 0
3 0 0
3 0 1
3 1 0
4 0 0

update @ 2024/3/10 01:23:03