1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
swat32
3 years ago
12

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. Y

ou would fill in the actual code that makes it happen. int main() { int TARGET
Computers and Technology
1 answer:
OverLord2011 [107]3 years ago
6 0

Answer:

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

…a) Include the last element, recur for n = n-1, sum = sum – set[n-1]

…b) Exclude the last element, recur for n = n-1.

If any of the above the above subproblems return true, then return true.

Explanation:

Using C++

// A recursive solution for subset sum problem

#include <stdio.h>

// Returns true if there is a subset of set[] with sun equal to given sum

bool isSubsetSum(int set[], int n, int sum)

{

// Base Cases

if (sum == 0)

return true;

if (n == 0 && sum != 0)

return false;

// If last element is greater than sum, then ignore it

if (set[n-1] > sum)

return isSubsetSum(set, n-1, sum);

/* else, check if sum can be obtained by any of the following

(a) including the last element

(b) excluding the last element */

return isSubsetSum(set, n-1, sum) ||

isSubsetSum(set, n-1, sum-set[n-1]);

}

// Driver program to test above function

int main()

{

int set[] = {3, 34, 4, 12, 5, 2};

int sum = 9;

int n = sizeof(set)/sizeof(set[0]);

if (isSubsetSum(set, n, sum) == true)

printf("Found a subset with given sum");

else

printf("No subset with given sum");

return 0;

}

Output:

Found a subset with given sum

You might be interested in
Which of the following goals states a quantifiable outcome of a project?
Ugo [173]

Answer:

An increase in revenue

Explanation:

We cannot predict how much revenue growth we are going to generate, and at what time. And hence, 2 and 3 are not an option here. Also, a TV science show has nothing to do with the quantifiable outcome of a project. And what is true is certainly that there is going to be an increase in revenue, which can certainly predict if we feel work was good and ended with good results. And hence the above option is the correct option for this question.

6 0
3 years ago
I NEED TO FIND OUT THE ANSWER!
vladimir1956 [14]

Answer:

the first action that should be taken is to back up the all important document that and by finishing doing that format the entire system...and i advise you should be choosing the best antivirus to protecting your computer

7 0
3 years ago
The line of code to the right will import the NumPy library. The "np" is an assigned name for the library.
mario62 [17]

Answer:

a. that is may become the signal

6 0
2 years ago
ABC Enterprises has three employees who work in the same building. The type of network they need is a _____. LAN MAN STAN WAN
algol [13]
The type of network they need is LAN
8 0
3 years ago
Read 2 more answers
Is this statement true or false?
-BARSIC- [3]

Answer:

THIS IS TRUE

Explanation:

but try to hurry up if the time is about to finish or try to find a quick way to wrap it up if the timing is too strict.

Hope this helped :)

7 0
2 years ago
Read 2 more answers
Other questions:
  • Sarah's research shows that business information management professionals also perform the duties of other professionals. Which
    9·1 answer
  • Good participation in music is strictly limited to those who perform well. true or false
    13·2 answers
  • Which principle of CSR requires that a business state facts fully and accurately?
    8·1 answer
  • Dustin is editing a SmartArt graphic. He wants all three shapes to be different colors.
    13·1 answer
  • While doing research on the Internet, what kind of website should you avoid because the information may be biased?
    11·1 answer
  • What is the gauge manifold made of
    14·1 answer
  • Gina is upgrading your computer with a new processor. She installs the processor into your motherboard and adds the cooling syst
    7·1 answer
  • Partes de la ventana principal de Microsoft excel 2013 con sus respectivas funciones
    14·1 answer
  • Search..
    14·1 answer
  • Discuss the impact printer and its types in detail?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!