24 const int capacity = 6;
25 using Objects = std::vector<std::pair<int, int>>;
26 Objects objects{ { 1, 3 }, { 2, 2 }, { 3, 65 }, { 1, 1 }, { 2, 2 },
27 { 4, 3 }, { 1, 1 }, { 10, 23 } };
28 auto size = [](std::pair<int, int> object) {
return object.first; }
30 auto value = [](std::pair<int, int> object) {
return object.second; }
34 std::cout <<
"Knapsack 0 / 1" << std::endl;
36 objects, capacity, std::back_inserter(result), value, size);
38 std::cout <<
"Max value " << maxValue.first <<
", Total size "
39 << maxValue.second << std::endl;
40 for (
auto o : result) {
41 std::cout <<
"{ size = " << o.first <<
", value = " << o.second <<
"} ";
43 std::cout << std::endl;
detail::knapsack_base< Objects, ObjectSizeFunctor, ObjectValueFunctor >::return_type knapsack_0_1_two_app(Objects &&objects, typename detail::FunctorOnRangePValue< ObjectSizeFunctor, Objects > capacity, OutputIterator out, ObjectValueFunctor value, ObjectSizeFunctor size)
detail
int main()
[Knapsack Example]