Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assg4.cc
- #include "backtrack.h"
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- int n = 0;
- int M = 0;
- vector<int> w_i_vector;
- vector<int> p_i_vector;
- vector<vector<int> > datavector;
- cout << "Please enter the number of integers to use (n): ";
- cin >> n;
- for(int w=0; w<n; w++)
- {
- int temp = 0;
- cout << "Please enter w_" << w+1 << ": ";
- cin >> temp;
- while(temp < 1)
- {
- cout << "ERROR! Please enter a positive integer: ";
- cin >> temp;
- }
- w_i_vector.push_back(temp);
- }
- for(int p=0; p<n; p++)
- {
- int temp = 0;
- cout << "Please enter p_" << p+1 << ": ";
- cin >> temp;
- while(temp < 1)
- {
- cout << "ERROR! Please enter a positive integer: ";
- cin >> temp;
- }
- p_i_vector.push_back(temp);
- }
- cout << "Please enter the maximum weight (M): ";
- cin >> M;
- //how to store this?
- vector<int> Mvec;
- Mvec.push_back(M);
- datavector.push_back(Mvec);
- for(int c=0; c<n; c++)
- {
- vector<int> tempvec;
- tempvec.push_back(w_i_vector[c]);
- tempvec.push_back(p_i_vector[c]);
- tempvec.push_back(NULL); //this will be the final soln value
- datavector.push_back(tempvec);
- }
- vector<int> solnvector;
- solnvector.push_back(M);
- solnvector.push_back(0);
- datavector.push_back(solnvector);
- void *data = &datavector;
- bool finished = false;
- bool* continuance = &finished;
- int *a = new int[n+1];
- for(int i=0; i<n; i++)
- {
- a[i] = NULL;
- }
- backtrack(a,0,data,2,continuance);
- for(unsigned l=1; l<(n+1); l++)
- {
- cout << datavector[l][2] << " ";
- }
- cout << endl;
- delete []a;
- delete continuance;
- //a = NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement