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
Design the program that reads two files and compares their contents. The program calls a method that reads the file one line at
Advocard [28]

Answer:

file1 = []

file2 = []

fileone = "lyric1.txt"

filetwo = "lyric2.txt"

def linereader( myfile, mylist):

   for line in open(myfile, "r") as file:

       line_read = readlines( line)

       mylist.append( line_read)

   file.close()

linereader( fileone, file1)

linereader( filetwo, file2)

# Assuming both files have same number of lines.

for index, item in enumerate(zip(file1, file2)):

   if item[0] != item[1]:

       print( index + 1, item)

Explanation:

The python code compares two files and returns the number and the lines from both files that do not match. The source code opens the files lyric1.txt and lyric2.txt reading each lines to different lists which are iterated to compare its items returning the number of the line and the unequal lines.

5 0
3 years ago
Give an example of how loops are used in programming Kturtle​
tankabanditka [31]

Answer:

Explanation:

KTurtle is an educational programming environment for turtle graphics. It is released under the open-source GNU General Public License and is part of the KDE Project since KDE3. KTurtle includes an IDE and a programming language which is loosely based on Logo and is intended for teaching programming.

5 0
3 years ago
Explain with example how does delay marriage help for population management​
nikdorinn [45]

Answer:

Explanation:

The population in western richer countries is decreasing but the population in some poorer developing countries is increasing and normally in the poorer communities where education is minimal or not encouraged then men and women tend to get married young and have many children. Population management is not necessary because when men and women are educated and have good standard of living with a good social system of caring for the old then married couples will tend to have one or two kids or none at all. Population control was practised by PrC and it managed to alleviate 60% of the people out if poverty and reduced the population by implementing one child policy. Now China has more male than female creating social problems of finding a wife. In the West with good social system to care for the elderly more couples are not having children. In the west where living conditions and educational level are better the Caucasian race is not having that many children as the other races in developing countries. Education and financial independence of women will encourage married women to have one or two kids so that they can still pursue their career after marriage. With modern contraception you can delay having children until you are ready for them. The concept of delaying marriage to reduce population does not hold true. However the whites’ population is decreasing every year as compared to the other non white races. The reason is that in the poorer non white countries the population is higher because of subservient position of the women who have no say in birth control

8 0
4 years ago
What are face shields intended to protect you from? (select best answer?
aivan3 [116]
Well it determends if there wearing them for sports or for fighting 
if it is for sports then they are protected from balls and such
if it is for fighting then they are protected from bullets arrows and anything else you could think of
they are used to shield your face
8 0
3 years ago
Read 2 more answers
Which of the following Information Technology career fields generally requires the lowest level of education for an entry-level
Art [367]
I believe the correct answer from the choices listed above is option A. The <span> Information Technology career fields that generally requires the lowest level of education for an entry-level position would be </span><span>Information Services and Support. Hope this answers the question.</span>
5 0
3 years ago
Read 2 more answers
Other questions:
  • --- is a set of applications that manages the activities and resources of a computer.
    12·1 answer
  • This LEGENDARY character made a much-celebrated comeback in 2017. What was the name of the villain he faced in this epic tale?
    7·2 answers
  • in Google, how should you phrase your search if you want to exclude a certain word from your results(for example,"chocolate")?
    14·1 answer
  • Beverly is creating a website for her new clothing company. Aside from including photographs, how can she use the index page to
    8·2 answers
  • What is the root of the tree?
    6·1 answer
  • Select the layer of the OSI model that is responsible for reformatting, compressing, and/or encrypting data in a way that the ap
    14·1 answer
  • PLEASE HELP ASAP
    15·1 answer
  • You text file begins with the following rows. The pattern is a description of the item to be repaired, its color, and the issue.
    14·1 answer
  • If you wish to install a new OS without disturbing the old one so that you can boot to either OS, what type of boot setup should
    6·1 answer
  • A thesis statement is the last sentence of the conclusion. It summarizes the entire paper.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!