Frknap
Frknap
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Item
{
int weight;
int value;
int index;
Item(int w, int v, int idx) : weight(w), value(v), index(idx) {}
};
return totalValue;
}
int main()
{
int n;
int W;
vector<Item> items;
cout << "Enter the weights and values of the items (weight value): " << endl;
for (int i = 0; i < n; ++i)
{
int weight, value;
cin >> weight >> value;
items.push_back(Item(weight, value, i));
}
double maxValue = fractionalKnapsack(W, items);
cout << "\nThe maximum value that can be obtained is: " << maxValue << endl;
return 0;
}
INPUT AND OUTPUT: