[algogeeks] Re: finding n numbers having particular sum

2011-04-21 Thread AmitMIST
Thanx @DON, was looking for it for a bit of time... I myself wrote some piece of code though urs is the better one On Apr 19, 10:21 am, Don wrote: > Here is the program with better documentation and a fix for the case > when sum is zero. > > // Number of elements to select from > const int

[algogeeks] Re: finding n numbers having particular sum

2011-04-19 Thread Don
Here is the program with better documentation and a fix for the case when sum is zero. // Number of elements to select from const int setSize = 20; // Unique integers to select from int set[setSize] = { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; // Desired sum of subset const int sum

[algogeeks] Re: finding n numbers having particular sum

2011-04-19 Thread Anders Ma
the program doesn't consider const in sum = 0. On Apr 19, 12:44 am, Don wrote: > const int setSize = 20; > int set[setSize] = > { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; > const int sum = 150; > > int rec[setSize]; > int recCount = 0; > int subset=0; > > void search(int *set, int se

Re: [algogeeks] Re: finding n numbers having particular sum

2011-04-18 Thread kamlesh yadav
@Don thanks, nice one, but can u give a little bit of explanation. On Mon, Apr 18, 2011 at 10:14 PM, Don wrote: > const int setSize = 20; > int set[setSize] = > { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; > const int sum = 150; > > int rec[setSize]; > int recCount = 0; > int subset=0

Re: [algogeeks] Re: finding n numbers having particular sum

2011-04-18 Thread kamlesh yadav
can you give some links pls On Mon, Apr 18, 2011 at 9:02 PM, Venki wrote: > It is called well known subset sum problem. Backtracking suits well > for such optimization problems. Read material on state space methods > of solving subset sum problem. > > Regards, > Venki. > > On Apr 18, 4:16 pm, ka

[algogeeks] Re: finding n numbers having particular sum

2011-04-18 Thread Don
const int setSize = 20; int set[setSize] = { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; const int sum = 150; int rec[setSize]; int recCount = 0; int subset=0; void search(int *set, int setSize, int sum) { int i; if (sum == 0) { printf("Subset %d:

[algogeeks] Re: finding n numbers having particular sum

2011-04-18 Thread Venki
It is called well known subset sum problem. Backtracking suits well for such optimization problems. Read material on state space methods of solving subset sum problem. Regards, Venki. On Apr 18, 4:16 pm, kamlesh yadav wrote: > given an array of elements (all elements are unique ) , given a sum >