Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Taken from Usaco Training Page.
Difficulty Gamma
Zero Sum
Question:
Consider the sequence of digits from 1 through
N in increasing order: 1 2 3 ... N.
Now insert either a '+' for addition or
a '-' for subtraction or a ' ' [blank] to run
the digits together between each pair of digits
(not in front of the first digit). Calculate
the result that of the expression and see if you
get zero.
Consider: 1-2 3-4 5+6 7.
This translates to 1 – 23 – 45 + 67 = 0.
Write a program that will find all sequences of
length N that produce a zero sum.
Input specification:
You will be given an integer N (3<=N<=9)
which is the last number of the sequence.
Output specification:
You are required to give all the possible
solutions for this sequence or "Impossible"
if none is found. Note: Use the order:
blank, + and -.
Sample Input I
7
|
Sample Input II
6
|
Sample Output I
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
|
Sample Output II
1 2+3-4-5-6
|
Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.
|