I am trying to resolve Fractional Knapsack problem (Maximum Value of the Loot), there is my code :
#include <iostream>
#include <vector>
#include <algorithm>
using std::vector;
double get_optimal_value(int capacity, vector<int> weights, vector<int> values) {
double value = 0.0;
vector<int> ratio;
for(int i=0; i<values.size(); i++) {
ratio.push_back(values[i]/weights[i]);
}
int a = 0;
while(capacity>0){
auto it = std::max_element(ratio.begin(), ratio.end());
a = std::max(capacity, *it);
capacity -= *it * a;
values = values + a * *it;
}
return value;
}
And I get the following error :
error: no match for ‘operator+’ (operand types are ‘std::vector’ and ‘int’)
For the line :
values = values + a * *it;