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
Gre4nikov [31]
4 years ago
7

Create a simple main() that solves the subset sum problem for any vector ofints. Here is an example of the set-up and output. Yo

u would fill in the actual code that makes it happen. I want the code to produce a result like the output please do not copy random stuff from google.Code:int main(){ int TARGET = 180; vector dataSet; vector choices; vector::iterator iter, iterBest; int k, j, numSets, max, masterSum; bool foundPerfect; dataSet.push_back(20); dataSet.push_back(12); dataSet.push_back(22); dataSet.push_back(15); dataSet.push_back(25); dataSet.push_back(19); dataSet.push_back(29); dataSet.push_back(18); dataSet.push_back(11); dataSet.push_back(13); dataSet.push_back(17); choices.clear(); cout << "Target time: " << TARGET << endl; // code provided by student iterBest->showSublist(); return 0; }
Computers and Technology
1 answer:
ivolga24 [154]4 years ago
8 0

Answer:

The main function is given below. Appropriate comments are made where necessary. In addition to this, I added a full code for the problem to help you understand it fully

Explanation:

// Sublist.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <iostream>

#include <vector>

using namespace std;

int sumInStack = 0;

int TARGET_SUM = 180;

vector<int> choices;

void subList(vector<int> data, int fromIndex, int endIndex);

void print();

int main()

{  

  vector<int> dataSet;

  int k, j, fromIndex,endIndex;

  bool foundPerfect;

  dataSet.push_back(20); dataSet.push_back(12);     dataSet.push_back(22);

  dataSet.push_back(15); dataSet.push_back(25);

  dataSet.push_back(19); dataSet.push_back(29);

  dataSet.push_back(18);

  dataSet.push_back(11); dataSet.push_back(13); dataSet.push_back(17);

  choices.clear();

  fromIndex=0;

  endIndex=dataSet.size();

  cout << "Target time: " << TARGET_SUM << endl;

  subList(dataSet, fromIndex, endIndex);

  // code provided by student

  system("pause");

  return 0;

}

void subList(vector<int> data, int fromIndex, int endIndex) {

       /*

       * Check if sum of elements stored in Stack is equal to the expected

       * target sum.

       *

       * If so, call print method to print the candidate satisfied result.

       */

       if (sumInStack == TARGET_SUM)

         {

          print();

       }

       for (int currentIndex = fromIndex; currentIndex < endIndex; currentIndex++)

         {

           if (sumInStack + data[currentIndex] <= TARGET_SUM)

             {

                  choices.push_back(data[currentIndex]);

               sumInStack += data[currentIndex];

               /*

               * Make the currentIndex +1, and then use recursion to proceed

               * further.

               */

           subList(data, currentIndex + 1, endIndex);

                  sumInStack -= choices.back();

                  choices.pop_back();

           }

       }

   }

void print()

{

    cout<<TARGET_SUM<<" = ";

    for(int i=0;i<choices.size();i++)

    {

         cout<<choices.at(i)<<"+";

    }

}

You might be interested in
Suppose end system A wants to send a large file to end system B. At a very high level, describe how end system A creates packets
kvasek [131]

Answer:

When we journey from a particular city to another city and we don’t really know the path then we ask for path and go on that which is just the same thing as packet switching.

Explanation:

Suppose system A intends to send packet to system B the steps and procedures are given below

1. A breakdown of large file into smaller bits of data on system A will first occur.

2.It attach separate headers for every portion of the file so that each portion looks like separate packet.

3.Header file in chunks will contain ip address of the file receiver which here is system B.

4. the Switch system will utilize the IP present in header to decide the link to destination.

6 0
4 years ago
A formal log-on procedure is the operating system’s last line of defense against unauthorized access.
Elina [12.6K]
The answer is A. true
7 0
3 years ago
How can IT infrastructure be linked to the business strategy of any organization
Anni [7]

Answer:

The overview of the situation is discussed in the following part.

Explanation:

It's indeed real that perhaps IT technology will have a strategic edge and improved market efficiency. IT technology can improve the protection, accessibility, and efficiency of any enterprise.

Numerous massive, small as well as medium-sized companies or beginning are currently preparing their growth plans by sustaining a stable IT infrastructure throughout the place that will ensure and increase their profitability.

<u>Those same years, the accompanying IT infrastructure is being used to connect the market strategy</u>:

  • Broadband and Wireless Connectivity,
  • Security and Risk Management,
  • IT Structure Strategy,
  • Performance Strategy, etc.
7 0
3 years ago
How could you insert a new row between rows 20 and 21?
love history [14]
<span>The Answer is C. Right-click row 21's row number, and then click Insert.

</span>
6 0
3 years ago
Read 2 more answers
Why are medical coders using encoded software
EastWind [94]
To keep the medical records confidential otherwise, hackers would take advantage of them and sell them to the highest bidder 
3 0
3 years ago
Other questions:
  • Gina's teacher has sent her a Word document that contains the names of all the students who are participating in the
    11·2 answers
  • Which best describes rfid technology?
    5·1 answer
  • Which of the following is the main consideration when choosing an appropriate outlet box?
    7·2 answers
  • Which of the following is the correct code to link the text "Sunny Days" to the website www.sunnysunshine.com?
    15·1 answer
  • MICR is an input or output devices
    5·1 answer
  • How do you copy and paste plz let me know
    14·2 answers
  • In what other game can kids line up in a row
    6·1 answer
  • How are Earth's plates made?
    14·1 answer
  • There are many reasons to convert to the decimal numbering system. Select the best answer. When checking numeric values in compu
    5·2 answers
  • Complete the sentence.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!