[algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-15 Thread bittu
if m getting question correct then the our task is to Given a total score n, print out all the combination to compose n. Examples: For n = 1, the program should print following: 1 For n = 2, the program should print following: 1 1 2 For n = 3, the program should print following: 1 1 1 1 2 2 1

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-15 Thread DIPANKAR DUTTA
use DP see careercup.. On Tue, Mar 15, 2011 at 10:43 PM, albert theboss alberttheb...@gmail.comwrote: @bittu : many over lapping sub problems available in ur case ... better try dp to get the efficient solution... @all : suggest algo for the case without repetition. -- You received this

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-14 Thread tech rascal
@sukhmeet: plz explain ur method if the no is 50 On Sun, Mar 13, 2011 at 8:24 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: I think it can be done like this that assume that the number is represented as 1.. like 4= , 3= 111 ans so on now if u have to fint the total number of ways then

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-14 Thread ravi teja
Use DP -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group

[algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-14 Thread Ralph Boland
On Mar 11, 9:33 am, saurabh agrawal saurabh...@gmail.com wrote: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers I suggest you 1) generate the numeric partitions of n. That's the lists of numbers in sorted order whose

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-14 Thread pacific pacific
My approach : partition(n) = 1 + partition(n-1) 2+partition(n-2) 3+partition(n-3) .. .. n-1+partition(1) n Assuming 1+2 and 2+1 as different. On Mon, Mar 14, 2011 at 11:53 PM, Aviral Gupta aviral@gmail.com wrote: you can use coin change problem as one of the solutions. Regards

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-13 Thread sukhmeet singh
I think it can be done like this that assume that the number is represented as 1.. like 4= , 3= 111 ans so on now if u have to fint the total number of ways then it is similar to placing a '+' sign in the mid places Like 3= 1 1 1 so possible are 1+11 (1+2) or 11+1 (2+1) or 1+1+1(1+1+1) hence 3

[algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-11 Thread Dave
This is a good place to use recursion. One thing you have to know is whether order matters. E.g., are 2 + 1 and 1 + 2 the same or different ways to represent 3 as a sum of positive integers. This choice will affect the way you write the recursive function. Dave On Mar 11, 9:33 am, saurabh

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-11 Thread saurabh agrawal
Do it assuming as two cases. On Fri, Mar 11, 2011 at 9:46 PM, Dave dave_and_da...@juno.com wrote: This is a good place to use recursion. One thing you have to know is whether order matters. E.g., are 2 + 1 and 1 + 2 the same or different ways to represent 3 as a sum of positive integers. This