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/d9/dec/unbounded__0__1__knapsack_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/unbounded_0_1_knapsack.cpp Source File

Go to the documentation of this file. 42namespace

unbounded_knapsack {

59 const

std::vector<std::uint16_t>& val,

60 const

std::vector<std::uint16_t>& wt,

61

std::vector<std::vector<int>>&

dp

) {

81

std::max(take, nottake);

94 const

std::vector<std::uint16_t>& val,

95 const

std::vector<std::uint16_t>& wt) {

98

std::vector<std::vector<int>>

dp

(

99

N, std::vector<int>(W + 1, -1));

113

std::uint16_t N1 = 4;

114

std::vector<std::uint16_t> wt1 = {1, 3, 4, 5};

115

std::vector<std::uint16_t> val1 = {6, 1, 7, 7};

116

std::uint16_t W1 = 8;

119

N1, W1, val1, wt1) == 48);

120

std::cout <<

"Maximum Knapsack value " 126

std::uint16_t N2 = 3;

127

std::vector<std::uint16_t> wt2 = {10, 20, 30};

128

std::vector<std::uint16_t> val2 = {60, 100, 120};

129

std::uint16_t W2 = 5;

132

N2, W2, val2, wt2) == 0);

133

std::cout <<

"Maximum Knapsack value " 139

std::uint16_t N3 = 3;

140

std::vector<std::uint16_t> wt3 = {2, 4, 6};

141

std::vector<std::uint16_t> val3 = {5, 11, 13};

142

std::uint16_t W3 = 27;

145

N3, W3, val3, wt3) == 27);

146

std::cout <<

"Maximum Knapsack value " 152

std::uint16_t N4 = 0;

153

std::vector<std::uint16_t> wt4 = {};

154

std::vector<std::uint16_t> val4 = {};

155

std::uint16_t W4 = 10;

157

N4, W4, val4, wt4) == 0);

158

std::cout <<

"Maximum Knapsack value for empty arrays: " 163

std::cout <<

"All test cases passed!"

<< std::endl;

Dynamic Programming algorithms.

std::uint16_t unboundedKnapsack(std::uint16_t N, std::uint16_t W, const std::vector< std::uint16_t > &val, const std::vector< std::uint16_t > &wt)

Wrapper function to initiate the unbounded knapsack calculation.

static void tests()

self test implementation

std::uint16_t KnapSackFilling(std::uint16_t i, std::uint16_t W, const std::vector< std::uint16_t > &val, const std::vector< std::uint16_t > &wt, std::vector< std::vector< int > > &dp)

Recursive function to calculate the maximum value obtainable using an unbounded knapsack approach.


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