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
2 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]2 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 resource helps a user access a cloud service?
gregori [183]

Answer B (Data storage system)

5 0
3 years ago
Evaluate if the following function is a good candidate to be placed in a library. Why or why not?
Anastaziya [24]

Answer:

No, this would not be a good candidate because it can't be used in creating new programs.

Explanation:

^

8 0
2 years ago
Read 2 more answers
Wireless networks use radio frequency (RF) or radio techniques, which allows wireless transmissions to reach out in all directio
tia_tia [17]

Answer: True

Explanation:

Yes, the given statement is true that that one of the quality of the wireless networks is that they uses the various radio techniques and the radio frequency.

 By using this techniques, the wireless transmission occur and it enable the connectivity and allow the direction of transmission to eavesdrop. It is one of the best technique as compared to the traditional method which include copper and fiber.

6 0
3 years ago
What is the purpose of the Zoom dialog box? to put the selected range in ascending order in a query to put the selected range in
AlekseyPX

The zoom dialog box helps to enter text and expressions in tight places, such as a property sheet or Query Design view. You can resize the zoom box and change the font. And the zoom box remembers the size and font each time you use it.

Use the

5 0
3 years ago
Read 2 more answers
Matthew is running a study on the effects of room temperature on performance on an algebra test. One group takes the test in a r
qaws [65]

Answer:

Independent variable is temperature

Explanation:

An equation has this form:    Y= f(x), where Y is dependent variable andX is independent variable.

In this case Y ( Dependent variable) is Perfomance in test, an it depends on x(Independent variable) wich is temperature.

7 0
3 years ago
Other questions:
  • When you are printing handouts, which of these can you do? A. Save paper by placing more than one slide per page. B. Check the f
    7·1 answer
  • Under what circumstances are composite primary keys appropriate?
    5·1 answer
  • Budgets help you to do all of the following expect
    15·2 answers
  • 0x400C (in hexadecimal)?
    8·1 answer
  • Translate We get up at 8 o'clock into Spanish in the box below:​
    9·1 answer
  • it is used to hold screws, jumpers, fasteners, and other small parts and prevent them from getting mixed together​
    15·2 answers
  • Chose the term that matches each definition.
    15·1 answer
  • How do you change your name on your brainly profile
    14·2 answers
  • PLEASE HELP! (NO LINKS)
    7·1 answer
  • ASAP 50 POINTS
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!