ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Переборные задачи > задача:


50715 - Zero Sum

Гость
• Обсуждение задачи (2)

Задачи раздела

• 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

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Taken from Usaco Training Page. Сложность Гамма

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