23 using Objects = std::vector<std::pair<int, int>>;
24 Objects objects{{1, 3}, {2, 2} , {3, 65} ,
25 {1, 1} , {2, 2} , {4, 3} , {1, 1} , {10, 23}};
26 const int capacity = 6;
27 auto size = [](std::pair<int, int> object) {
return object.first;};
28 auto value = [](std::pair<int, int> object) {
return object.second;};
31 std::cout <<
"Knapsack unbounded" << std::endl;
33 capacity, std::back_inserter(result),
36 std::cout <<
"Max value " << maxValue.first <<
", Total size "
37 << maxValue.second << std::endl;
38 for(
auto o : result) {
39 std::cout <<
"{ size = " << o.first <<
", value = " << o.second <<
"} ";
41 std::cout << std::endl;
detail::knapsack_base< Objects, ObjectSizeFunctor, ObjectValueFunctor >::return_type knapsack_unbounded(Objects &&objects, detail::FunctorOnRangePValue< ObjectSizeFunctor, Objects > capacity, OutputIterator out, ObjectSizeFunctor size, ObjectValueFunctor value=ObjectValueFunctor())
Solution to the knapsack problem.