HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Exhaustive search & Backtracking > problem:


50715 - Zero Sum

Guest
• Discussion of problem (2)

Section problems

• 50367 - Bar Codes
• 50250 - The Knight
• 50707 - Rebus
• 50265 - Liars and Knights
• 51071 - Phalanx-2
• 50715 - Zero Sum
• 50711 - Snail Trails
• 50472 - Minimum Sum Triangle
• 50306 - Beautiful Numbers
• 50716 - All Palindromes
• 50714 - The knight
• 50713 - Castle and the girls
• 50710 - Permutations
• 50709 - k-ary Strings

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