Advertisement
Guest User

Untitled

a guest
Mar 30th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. //Assg4.cc
  2.  
  3. #include "backtrack.h"
  4. #include <iostream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n = 0;
  12.     int M = 0;
  13.     vector<int> w_i_vector;
  14.     vector<int> p_i_vector;
  15.     vector<vector<int> > datavector;
  16.  
  17.     cout << "Please enter the number of integers to use (n): ";
  18.     cin >> n;
  19.     for(int w=0; w<n; w++)
  20.     {
  21.         int temp = 0;
  22.         cout << "Please enter w_" << w+1 << ": ";
  23.         cin >> temp;
  24.         while(temp < 1)
  25.         {
  26.             cout << "ERROR! Please enter a positive integer: ";
  27.             cin >> temp;
  28.         }
  29.         w_i_vector.push_back(temp);
  30.     }
  31.     for(int p=0; p<n; p++)
  32.     {
  33.         int temp = 0;
  34.         cout << "Please enter p_" << p+1 << ": ";
  35.         cin >> temp;
  36.         while(temp < 1)
  37.         {
  38.             cout << "ERROR! Please enter a positive integer: ";
  39.             cin >> temp;
  40.         }
  41.         p_i_vector.push_back(temp);
  42.     }
  43.    
  44.     cout << "Please enter the maximum weight (M): ";
  45.     cin >> M;
  46.     //how to store this?
  47.     vector<int> Mvec;
  48.     Mvec.push_back(M);
  49.     datavector.push_back(Mvec);
  50.    
  51.    
  52.     for(int c=0; c<n; c++)
  53.     {
  54.         vector<int> tempvec;
  55.         tempvec.push_back(w_i_vector[c]);
  56.         tempvec.push_back(p_i_vector[c]);
  57.         tempvec.push_back(NULL); //this will be the final soln value
  58.         datavector.push_back(tempvec);
  59.     }
  60.     vector<int> solnvector;
  61.     solnvector.push_back(M);
  62.     solnvector.push_back(0);
  63.     datavector.push_back(solnvector);
  64.  
  65.     void *data = &datavector;
  66.     bool finished = false;
  67.     bool* continuance = &finished;
  68.     int *a = new int[n+1];
  69.     for(int i=0; i<n; i++)
  70.     {
  71.         a[i] = NULL;
  72.     }
  73.  
  74.     backtrack(a,0,data,2,continuance);
  75.  
  76.     for(unsigned l=1; l<(n+1); l++)
  77.     {
  78.         cout << datavector[l][2] << " ";
  79.     }
  80.     cout << endl;
  81.  
  82.     delete []a;
  83.     delete continuance;
  84.     //a = NULL;
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement