#P1473. [USACO2.3] 零的数列 Zero Sum
[USACO2.3] 零的数列 Zero Sum
Description
Consider an increasing sequence of numbers from to : .
Insert + for addition, - for subtraction, or (a space) for blank between each pair of consecutive numbers (for example, 1-2 3 equals 1-23). Do not insert any symbol before the first number.
Evaluate the resulting expression and determine whether its value is . Write a program to find all expressions of length whose value is zero.
Input Format
A single line containing an integer ().
Output Format
In ASCII order, output all expressions obtained by inserting +, -, or (space) between each pair of consecutive numbers such that the resulting expression evaluates to . Print one expression per line.
7
1+2-3+4-5-6+7
1+2-3-4+5+6-7
1-2 3+4+5+6+7
1-2 3-4 5+6 7
1-2+3+4-5+6-7
1-2-3-4-5+6+7
Hint
Translated from NOCOW.
USACO 2.3.
Translated by ChatGPT 5
京公网安备 11011102002149号