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
Polaroid had a unique competitive advantage for many years until it forgot to observe competitive intelligence. The firm went ba
Snowcat [4.5K]

Answer:

false

Explanation:

Based on the information provided within the question it can be said that the statement being made is false. This statement does not exemplify Porter's threat of new entrants, since this talks about the threat of new companies entering the same market with the same product in order to compete with the existing competitors in that market. In this scenario the new companies that eventually made Polaroid Bankrupt had an innovative new technology and which people starting using and left the entire Polaroid Market behind.

8 0
3 years ago
Under which menu would you be able to see the number of continuous track minutes available on each mounted hard drive at the cur
Crazy boy [7]

Answer:

looooollll

Explanation:

yooooooooo u good

3 0
2 years ago
Complete the statement below using the correct term.<br>Website managers use<br>every day​
Leni [432]

Answer:

computers

Explanation:

8 0
3 years ago
Read 2 more answers
When artists have a successful career, there is sometimes the need to collect all their works in an anthology album. Given main(
elixir [45]

Answer:

Answered below

Explanation:

public class BoxSet extends Album{

private boolean isCompleteWork;

private int numDiscs;

public void setIsCompleteWorks( boolean cw){isCompleteWorks = cw;

}

public boolean getCompleteWorks(){

return isCompleteWorks;

}

public void setNumDiscs(int discs){

numDiscs = discs;

}

public int getNumDiscs(){

return numDiscs;

}

public void printInfo(){

super.printInfo();

System.out.print(isCompleteWorks);

System.out.print(numDiscs);

}

}

3 0
3 years ago
For what two reasons is it important to add comments to a program?​
Firdavs [7]
Answer: 1. They can easily understand the logic behind solving any problem 2. Comments may help you to memorize your logic that you have written while writing that code.
7 0
3 years ago
Other questions:
  • propose,two new ,proudly South African ways,which you can visualize that the IoT,can be used at work to make life better.
    12·1 answer
  • Which would be a responsible use of technology used by victims of cyberbullying? finding ways to strike back at bullies online.
    15·1 answer
  • Which details apply to a financing contract? Check all that apply
    10·2 answers
  • Which of the following code correctly registers a handler with a button btOK?a. btOK.setOnAction(e -&gt; System.out.println("Han
    6·1 answer
  • Which allows for saving a setting on one device and having the setting synchronize to other devices? Choose two answers.
    12·1 answer
  • What are the two types of modern wind turbines?
    8·1 answer
  • Two stations running TCP/IP are engaged in transferring a file. This file is 1000MB long, the payload size is 100 bytes, and the
    14·1 answer
  • Clicking a _____ name opens a drop-down list of commands and options. Select one: a. menu b. status bar c. ribbon d. toolbar
    15·1 answer
  • When you navigate inside a compressed folder, you click the
    6·1 answer
  • Help!!! Photography class!! ASP
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!