Strange Sequences - Solve this Problem

Problem Statement
Ms. Anna is very naughty in her classes and due to this her teacher has given her a punishment. Her teacher asked her to create a program for a positive integer i , which can find all possible sequences of positive integers x1, x2, ..., xp such that the sum of all p elements of the above sequence is equal to i and for each r, 1 <= r < p we have x[sub]r+1[/sub]- x[sub]r[/sub] in {-2, 0, 3}. Please help her in creating this program.

Input/Output Specs​Input Specs
In the first line you're given i ( 0 < i ≤ 10 ).

Output Specs
You need to output result to variable output1 as string. Sequences must be given in the lexicographic order, with each sequence enclosed in { }. The numbers within each sequence enclosed in { } must be separated by comma.

Note: In case there is no possible solution, you need to return -999 as output.

Examples​Example 1
Input:
2
Output:
{1,1}{2}

Example 2
Input
3
Output
{1,1,1}{3}

Example 3
Input
4
Output
{1,1,1,1}{2,2}{3,1}{4}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • PraveenKumar Purushothaman

    @praveenkumar-66Ze92 • May 11, 2012

    Inviting all the computer geeky people...
    #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#, #-Link-Snipped-#

  • Anoop Kumar

    @anoop-kumar-GDGRCn • May 13, 2012

    Example 2
    Input
    3
    Output
    {1,1,1}{3}

    I think it should be:
    {1,1,1}{1,2}{3}
    Am I right??