A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/db/d16/0__1__knapsack_8cpp.html below:

TheAlgorithms/C++: dynamic_programming/0_1_knapsack.cpp File Reference

Function to test the above algorithm.

96 {

97

98 const int n1 = 3;

99 std::array<int, n1> weight1 = {10, 20, 30};

100 std::array<int, n1> value1 = {60, 100, 120};

101 const int capacity1 = 50;

103 capacity1, weight1, value1);

104 const int expected_max_value1 = 220;

105 assert(max_value1 == expected_max_value1);

106 std::cout << "Maximum Knapsack value with " << n1 << " items is "

107 << max_value1 << std::endl;

108

109

110 const int n2 = 4;

111 std::array<int, n2> weight2 = {24, 10, 10, 7};

112 std::array<int, n2> value2 = {24, 18, 18, 10};

113 const int capacity2 = 25;

115 capacity2, weight2, value2);

116 const int expected_max_value2 = 36;

117 assert(max_value2 == expected_max_value2);

118 std::cout << "Maximum Knapsack value with " << n2 << " items is "

119 << max_value2 << std::endl;

120}

int maxKnapsackValue(const int capacity, const std::array< int, n > &weight, const std::array< int, n > &value)

Picking up all those items whose combined weight is below the given capacity and calculating the valu...


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4