The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Create a simple main() that solves the subset sum problem for any vector ofints. Here is an example of the set-up and output. You would fill in the actual code that makes it happen.
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; }
Finally, you are not finding all solutions, just one representative solution. There may be other subsets that do the job, but our algorithm only finds the one. (If youwant to show all the solutions, that's fine.)
A run for above would look like this:
Target time: 180 Sublist ----------------------------- sum: 179 array[0] = 20, array[1] = 12, array[3] = 15, array[4] = 25, array[5] = 19, array[6] = 29, array[7] = 18, array[8] = 11, array[9] = 13, array [10] = 17 Press any key to continue . . .
Notice how the target is not precisely met. Usually it is, so if you vary the target, you'll find that you can a perfectly matching sum.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll