@Don thanks,  nice one, but can u give a little bit of explanation.

On Mon, Apr 18, 2011 at 10:14 PM, Don <dondod...@gmail.com> 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 setSize, int sum)
> {
>        int i;
>        if (sum == 0)
>        {
>                printf("Subset %d: {%d", ++subset,rec[0]);
>                for(i = 1; i < recCount; ++i)
>                        printf(",%d", rec[i]);
>                printf("}\n");
>        }
>        else if (sum > 0)
>        {
>                for(i = 0; i < setSize; ++i)
>                {
>                        rec[recCount++] = set[i];
>                        search(set, i, sum-set[i]);
>                        --recCount;
>                }
>        }
> }
>
>
> int main(int argc, char* argv[])
> {
>        search(set, setSize, sum);
>
>        return 0;
> }
>
>
> On Apr 18, 6:16 am, kamlesh yadav <kamleshlu2...@gmail.com> wrote:
>> given an array of elements (all elements are unique ) , given a sum
>> s   find all the subsets having sum s.
>>
>> for ex  array {5,9,1,3,4,2,6,7,11,10}
>>
>> sum is 10
>>
>> possible subsets are     {10},  {6,4}     ,{7,3}      {5,3,2}
>> {6,3,1}  etc.    there can be many more.
>> also find the total number of these subsets
>
> --
> 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 at 
> http://groups.google.com/group/algogeeks?hl=en.
>
>



-- 
Kamlesh Kumar Yadav
MCA  Department of Computer Science
Delhi University

-- 
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 at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to