Create a simple main() that solves the subset sum problem for any vector of ints
ID: 638072 • Letter: C
Question
Create a simple main() that solves the subset sum problem for any vector of ints. Here is an example of the set-up and output. You would fill in the actual code that makes it happen.
Finally, you are not finding all solutions, just one representative solution. There may be other subsets that do the job, but our algorithm only finds the one. (If youwant to show all the solutions, that's fine.)
A run for above would look like this:
Notice how the target is not precisely met. Usually it is, so if you vary the target, you'll find that you can a perfectly matching sum.
Explanation / Answer
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.
Let isSubSetSum(int set[], int n, int sum) be the function to find whether there is a subset of set[] with sum equal to sum. n is the number of elements in set[].
The isSubsetSum problem can be divided into two subproblems
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.