Question: Write a C++ program to solve the problem Note that the elements in the subset should be output in non-decreasing order. Note that the elements

Write a C++ program to solve the problemWrite a C++ program to solve the problem Note that the elements

Note that the elements in the subset should be output in non-decreasing order.

Note that the elements in the subset should be output in non-decreasing order.

Note that the elements in the subset should be output in non-decreasing order.

in the subset should be output in non-decreasing order. Note that the

2,3,10

-7,10,12

Note also that even the sum of elements in {2, 3, -7, 17} = 15, but the number of elements exceed 3, this will not be considered as a correct output.

Sample input.txt file (note that T = {0, 4, 6, -2, 20}):

5

2

-9

0

4

6

-2

20

Only the following output will be correct.

No such a subset!

Sample input.txt file (note that T = {2, 9, 8, 1}):

4

2

10

2

9

8

1

Either one of the following outputs will be considered correct:

2, 8

1, 9

Given three integers, n, x, and S; and a set T of n integers, report a subset (you are only required to output one subset even if there are multiple solutions) of size smaller than or equal to x such that the sum of the integers in this subset equals S. Remarks (you MUST follow the instructions below): - Name the program as subset-sum. - The program will read in an input file, called input.txt. The input file contains 3+n lines. The first line is the integer n, the second line is the integer x, and the third line is the integer S. Then, the subsequent n lines containing the elements of the set T, with each line contains one distinct element of T. - You can assume that there is no error in the input file and there are no duplicate elements in T. - If there exists a subset with size

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!