HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Winner's Camp > problem:


07. 50715 - Zero Sum

Guest
• Discussion of problem (2)

Volume problems

• 04. 50649 - Puzzle
• 01. 50722 - Scientist's problem
• 02. 50376 - Sequences
• 05. 50713 - Castle and the girls
• 08. 50370 - Number of rectangles in ...
• 09. 50716 - All Palindromes
• 10. 50475 - Voice advertising
• 11. 50476 - Meditation
• 07. 50715 - Zero Sum

Feedback

If you notice incorrect translations in Contester, please let author know.

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


Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru