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
The diagram shows the positions of the Sun, Earth, and Moon during each moon phase. When viewed from Earth, at what point does t
goldfiish [28.3K]

Answer:

B

Explanation:

when it is on the same side of Earth as the Sun because it appears all black because of the shadow

7 0
2 years ago
Convert the following into binary system<br>and vice versa.<br>106​
notka56 [123]
It would be 1101010 in binary
4 0
3 years ago
Read 2 more answers
Wireless technology is best described as a/an
IgorLugansk [536]

Answer:

mobile computing system

Explanation:

6 0
4 years ago
Read 2 more answers
A _____ movement tries to improve a part of society, usually through legal methods.
arlik [135]

Answer:

Don’t know lol but look it up on g00gle and she will have the answr

Explanation:

3 0
3 years ago
Read 2 more answers
A time-saving strategy that helps define unfamiliar words involves using
yuradex [85]

The correct answer is A. Familiar words for clues

Explanation:

Finding unfamiliar words is common while reading, especially in texts that belong to a specific field such as medicine, technology, etc. This can be handled through multiple strategies such as using a dictionary, guessing the meaning of the word based on its parts, and using context clues.

In this context, one of the easiest and most time-saving strategy is the use of context clues that implies using the familiar words as clues to guess the meaning of an unfamiliar word. This is effective because in most cases the meaning of an unknown word can be determined using the context of the word or words around the unknown word. Also, this strategy takes little time because you only need to analyze the sentence or paragraph where the unknown word is. Thus, the time-saving strategy to define unfamiliar words involves using familiar words for clues.

6 0
3 years ago
Read 2 more answers
Other questions:
  • 6. When you don't have enough room to stop, you may _______ to avoid what's in front of you.
    14·1 answer
  • Describe the use of technology in the promotional function
    5·2 answers
  • True or false. Embedding only part of a font is called presetting.
    14·1 answer
  • Which type of storage disk and disk drive can be used in the given situation? Amy wants to borrow an interesting movie from Bruc
    10·2 answers
  • Let's say that you're the sole IT person in your company, and your boss wants a way to block certain websites from employees. Wh
    6·2 answers
  • What kind of information can be found in a ROM:
    14·1 answer
  • Write a function template that accepts an argument and returns its absolute value. The absolute value of a number is its value w
    11·1 answer
  • The intelligence displayed by humans and other animals is termed?
    15·1 answer
  • Which company introduce the first Minicomputer in 1960.​
    8·2 answers
  • So has anyone opened the link/file those people are giving out as answers? Like what are they, viruses, answers, nothing??? Some
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!