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
In multi-channel funnel reports, how are default conversions credited?
g100num [7]

The Multi-Channel Funnels reports are generated from conversion paths, the sequences of interactions (i.e., clicks/referrals from channels) that led up to each conversion and transaction. In the reports, channels are credited according to the roles they play in conversions—how often they assisted and/or completed sales and conversions.

6 0
2 years ago
Which of the following is true of equilibrium? *
SashulF [63]
B, it’s when the supply and demand are equal
7 0
2 years ago
This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by
stira [4]

Answer:

Here is the C program:

#include <stdio.h>  //to use input output functions

int main(void) {   //start of main function

 int arrowBaseHeight = 0;  //stores value for arrow base height

int  arrowBaseWidth = 0;  //stores value for arrow base width

 int arrowHeadWidth = 0 ;  //stores value for arrow head width

 int i, j;  //to traverse through the rows and columns

 printf("Enter arrow base height:\n");  //prompts user to enter arrow base height value

 scanf("%d", &arrowBaseHeight);  //reads input value of arrow base height

 printf("Enter arrow base width:\n");  //prompts user to enter arrow base width value

 scanf("%d", &arrowBaseWidth);  //reads input value of arrow base width

 while (arrowHeadWidth <= arrowBaseWidth)  {   //iterates as long as the value of arrowHeadWidth is less than or equals to the value of arrowBaseWidth  

     printf("Enter arrow head width:\n");   //prompts user to enter arrow head width value

     scanf("%d", &arrowHeadWidth);   //reads input value of arrow head width

     printf("\n"); }

 for (i = 0; i < arrowBaseHeight; i++)    {   //iterates through rows

     for (j = 0; j < arrowBaseWidth; j++)  {   //iterates through columns

         printf("*");       }   //prints asterisks

     printf("\n");   }   //prints a new line

 for (i = arrowHeadWidth; i > 0; i--)    {   //loop for input length

     for (j = i; j > 0; j--)        {   //iterates for triangle ( to make arrow head)

         printf("*");       }   //prints asterisks

     printf("\n");   }  } //prints new line

Explanation:

The program asks to enter the height of the arrow base, width of the arrow base and the width of arrow head. When asking to enter the width of the arrow head, a condition is checked that the arrow head width arrowHeadWidth should be less than or equal to width of arrow base arrowBaseWidth. The while loop keeps iterating until the user enters the arrow head width larger than the value of arrow base width.  

The loop is used to output an arrow base of height arrowBaseHeight.

The nested loop is being used which as a whole outputs an arrow base of width arrowBaseWidth. The inner loop draws the stars and forms the base width of the arrow, and the outer loop iterates a number of times equal to the height of the arrow.

The last nested loop is used to output an arrow head of width arrowHeadWidth. The inner loop forms the arrow head and prints the stars needed to form an arrow head.  

The screenshot of output is attached.

8 0
3 years ago
Access to a computer can be controlled using a ____ password.
slamgirl [31]
Yes it can be control by a USER ( administrator and having a MASTER password) 
8 0
3 years ago
What are the things you are considering before uploading photos on social media?
Lady_Fox [76]

How it could affect me if an employer (future or current) sees it and whether or not I would want strangers to be able to view it.

I'm pretty sure the general rule of advice is that if you wouldn't want your mother to see it, you probably shouldn't post it.

3 0
3 years ago
Other questions:
  • The ___ of a worksheet defines its appearance
    13·1 answer
  • What landforms are likely to form at this boundary
    15·1 answer
  • __________ is the order of arrangement of files and folders.
    6·1 answer
  • The first numerical control machine tool was demonstrated in 1952 in the United States at the Massachusetts Institute of Technol
    14·1 answer
  • Felicia is a computer programmer.
    13·1 answer
  • MORE FREEE POINTS AYEEE
    7·2 answers
  • If the three operations were combined, O(logN) + O(N) * O(logN) + 1, the overall algorithm cost would be:________
    6·1 answer
  • Please
    14·1 answer
  • When should you create an outline?
    7·1 answer
  • Simon would have regarded with impotent fury the disturbance between the North and the South, as it left his descendants strippe
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!