#P2404. 自然数的拆分问题

自然数的拆分问题

Description

Any natural number nn greater than 11 can be decomposed into a sum of several natural numbers that are each less than nn. Given a natural number nn, list all decompositions of nn into a sum of natural numbers, where every addend is less than nn. In each decomposition, the numbers must be written in nondecreasing order. Then output these sequences in lexicographic order, with lexicographically smaller sequences printed first.

Input Format

Input: a single natural number nn.

Output Format

Output: several addition expressions. Print one decomposition per line as a1+a2++aka_1+a_2+\dots+a_k, where each aia_i is a natural number less than nn, the sequence is in nondecreasing order, and the lines are sorted in lexicographic order.

7

1+1+1+1+1+1+1
1+1+1+1+1+2
1+1+1+1+3
1+1+1+2+2
1+1+1+4
1+1+2+3
1+1+5
1+2+2+2
1+2+4
1+3+3
1+6
2+2+3
2+5
3+4

Hint

Constraints: 2n82 \leq n \le 8.

Translated by ChatGPT 5