Re: [algogeeks] Print Subsets
@immanuel...i don't think it will..even if u think it does, provide any sample test case On 5/21/11, immanuel kingston kingston.imman...@gmail.com wrote: I think your soln will print repetitions also. On Mon, May 16, 2011 at 2:34 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: *int ref[] = {2,3,6,7,8};* *void printcombination(int n,int index,int i) { static int a[100]; int j; if (n == 0) { for(j=0;jindex;j++) printf(%d ,a[j]); printf(\n); } else if(n0) { for(j=i;j5;j++) { a[index]=ref[j]; printcombination(n-ref[j],index+1,j); } } } * *main() { int n; printf(enter value of n :); scanf(%d,n); printcombination(n,0,0); } * On Fri, May 13, 2011 at 2:40 AM, amit amitjaspal...@gmail.com wrote: Given a set of numbers eg:{2,3,6,7,8} . any one who is playing the game can score points only from this set using the numbers in that set. given a number, print all the possible ways of scoring that many points. Repetition of combinations are not allowed. eg: 1. 6 points can be scored as 6 3+3 2+2+2 2. 7 can be scored as 7 2+2+3 but 2+3+2 and 3+2+2 is not allowed as they are repetitions of 2+2+3 -- 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. -- PIYUSH SINHA IIIT, Allahabad -- 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. -- 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- 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.
Re: [algogeeks] Print Subsets
I think your soln will print repetitions also. On Mon, May 16, 2011 at 2:34 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: *int ref[] = {2,3,6,7,8};* *void printcombination(int n,int index,int i) { static int a[100]; int j; if (n == 0) { for(j=0;jindex;j++) printf(%d ,a[j]); printf(\n); } else if(n0) { for(j=i;j5;j++) { a[index]=ref[j]; printcombination(n-ref[j],index+1,j); } } } * *main() { int n; printf(enter value of n :); scanf(%d,n); printcombination(n,0,0); } * On Fri, May 13, 2011 at 2:40 AM, amit amitjaspal...@gmail.com wrote: Given a set of numbers eg:{2,3,6,7,8} . any one who is playing the game can score points only from this set using the numbers in that set. given a number, print all the possible ways of scoring that many points. Repetition of combinations are not allowed. eg: 1. 6 points can be scored as 6 3+3 2+2+2 2. 7 can be scored as 7 2+2+3 but 2+3+2 and 3+2+2 is not allowed as they are repetitions of 2+2+3 -- 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. -- PIYUSH SINHA IIIT, Allahabad -- 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. -- 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.
Re: [algogeeks] Print Subsets
its DP problem can be solved in O(m*n) where m is number of elements in array and n is value of the given number. -- 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.
Re: [algogeeks] Print Subsets
Correct. Its a variant of Knapsack problem. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at 4:53 PM, anshu mishra anshumishra6...@gmail.comwrote: its DP problem can be solved in O(m*n) where m is number of elements in array and n is value of the given number. -- 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. -- 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.