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

Сборники > Winner's Camp > задача:


07. 50715 - Zero Sum

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

Задачи сборника

• 04. 50649 - Puzzle
• 01. 50722 - Problemi i shkencetarit
• 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

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

Если у вас есть предложения или пожелания по работе 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