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
When LDAP traffic is made secure by using Secure Sockets Layer (SSL) or Transport Layer Security (TLS), what is this process cal
Simora [160]

Answer:

Authorization is granting permission for admittance. ACLs provide file system security for protecting files managed by the user. Rule-Based Access Control can be changed by users.

Explanation:

8 0
2 years ago
Text that is heavier or darker than other text in the document is considered _____.
kvv77 [185]

The text that is heavier or darker than other text in a document is considered  Bold.

Hope this helped!~

7 0
3 years ago
Read 2 more answers
Which of the following statements isNOT true about abstract data types (ADTs)?A list is anexample of an ADT.ADTs hide theimpleme
Fynjy0 [20]

Answer:

Java provide all the ADTs you need,therefore you do not need to create any newones.

This statement is not true.

Explanation:

ADTs are those data types which we use but we didn't know their inner working that is how it is working what is happening inside.It is commonly used for Data Structures for example:- In stack we use push and pop operations to insert and to delete element from a stack respectively but we didn't know how it is happening inside.How the stack is implemented and etc.Java provides most of the ADT's but not all.

5 0
2 years ago
Construct a SQL query that displays a list of colleges, their sity/state, the accrediting agency, and whether or not the school
Alex787 [66]

Answer:

SELECT college, city_state, accre_agency, distance LIMIT 10

Explanation:

Given

Table name: College

See attachment for table

Required

Retrieve top 10 college, state, agency and school distance from the table

To retrieve from a table, we make use of the SELECT query

The select statement is then followed by the columns to be selected (separated by comma (,))

So, we have:

SELECT college, city_state, accre_agency, distance

From the question, we are to select only first 10 records.

This is achieved using the LIMIT clause

i.e. LIMIT 10 for first 10

So, the complete query is:

SELECT college, city_state, accre_agency, distance LIMIT 10

6 0
3 years ago
what is the best book or website to learn mechanical machine design? . high detail ,easy to under stand .
Vadim26 [7]
WERE IS A B C D I CANT GIVE YOU ANSWER
7 0
3 years ago
Other questions:
  • When using the boolean data type, we encapsulate the data in what symbol?
    11·2 answers
  • Where is a 3D modeler most likely to work?
    6·1 answer
  • . List 5 types of exploits from cybercrime and provide brief definition. (2.5 Marks)
    5·1 answer
  • design a relational database in EER for bike helmets and their reviews. a bike helmet has a name and color attributes. a bike co
    12·1 answer
  • Describe the different non-printing characters,​
    11·1 answer
  • Who is the intended audience of a pseudocode document?
    14·1 answer
  • Which of these five are Netflix Originals?1/5
    5·1 answer
  • Write a list comprehension that creates a list containing the numbers that result from the values 1 through 10 being multiplied
    15·1 answer
  • Write an alogrithm to display the first ten even numbers​
    6·1 answer
  • 3. What of the following is the main components of computer system?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!