#P2404. 自然数的拆分问题
自然数的拆分问题
Description
Any natural number greater than can be decomposed into a sum of several natural numbers that are each less than . Given a natural number , list all decompositions of into a sum of natural numbers, where every addend is less than . 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 .
Output Format
Output: several addition expressions. Print one decomposition per line as , where each is a natural number less than , 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: .
Translated by ChatGPT 5
京公网安备 11011102002149号