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
Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would w
svet-max [94.6K]

Answer:

dataFile << salary;

Explanation:

To write salary to a file (payroll.dat) using ofstream, you make use of the following instruction:

<em>ofstream dataFile; </em>

<em>myfile.open ("payroll.dat"); </em>

<em>myfile <<salary; </em>

<em>myfile.close();</em>

<em />

This line creates an instance of ofstream

<em>ofstream dataFile; </em>

This line opens the file payroll.dat

<em>myfile.open ("payroll.dat"); </em>

This is where the exact instruction in the question is done. This writes the value of salary to payroll.dat

<em>myfile <<salary; </em>

This closes the opened file

<em>myfile.close();</em>

<em />

<em />

8 0
2 years ago
Could someone give an example or tell me what all of these mean? (For internet source citing) Evaluation: • Domain Name: • Autho
koban [17]

Evaluation-the making of a judgment about the amount, number, or value of something; assessment

Domain Name-Is a websites name (ex-Google)

Authoritativeness-The quality of possessing authority. The quality of trustworthiness and reliability.

Accuracy-the quality or state of being correct or precise

Timeliness-the fact or quality of being done or occurring at a favorable or useful time.

Objectivity-the quality of being objective.

Writing Style and Mechanics-Style has to do with how a piece of writing sounds. Everyone has a style which develops along with their writing.

Paragraph structure: Each paragraph should begin with a topic sentence that provides an overall understanding of the paragraph. ...

Sentence length: Sentences should be kept as short as possible so that their structure is simple and readable.

Graphics-are visual images or designs

Links- is an open source text and graphic web browser with a pull-down menu system.

8 0
2 years ago
Consider two different implementations of the same instruction set architecture (ISA). The instructions can be divided into four
PSYCHO15rus [73]

Answer: Find answers in the attachments

Explanation:

3 0
3 years ago
1:A presentation program which is developed by Microsoft
LekaFEV [45]
Option 3: PowerPoint.
4 0
2 years ago
Read 2 more answers
What are the steps to configure user information in a document?
chubhunter [2.5K]

Answer:

file, properties, options, general

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • You are reluctant to write an extra credit book report because you are afraid that your language and punctuation skills are not
    11·1 answer
  • Write the importance of cyber law? In point .<br>​
    10·2 answers
  • Exit network systems, information support, and software development are all careers in which career cluster?
    10·1 answer
  • After configuring a static IP address on a desktop computer, the technician finds that he cannot communicate with other devices
    10·1 answer
  • Give two reasons why it is important to upgrade your browser when a new version becomes available.
    8·1 answer
  • Error messages begin with the ____ symbol.
    6·2 answers
  • Which of the following is most accurate?
    10·1 answer
  • A good machine should have the mechanical advantage of......?​
    7·1 answer
  • Is a device used to test the network connection.
    11·2 answers
  • The technique that allows you to have multiple logical lans operating on the same physical equipment is known as a.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!