please tell me how can I get paths to get the subset with given sum (dp). I got stuck on how to print subsets.
Subset sum problem - to find all the subsets with given sum
@yashme7125 we can use recusion to print all the subsets
first we find which numbers we can form using the elements ans make a 2d dp array
dp[i][j] mean if we can form j as sum using the first i elements (as you already implemented) now we will use recursion and see if we can take current number or not by 2 ways:
- if the numbers if less than equal to current sum
- if we can take this number can we make sum-elements using the array elements
and if both the conditions satisfy then we include this number in our list and then check again and at lasta if we have remaning sum as zero then we print our answer
Coding Blocks IDE
this is the implemented code you can see and if still have any dout please let me know
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.