@@ -39,8 +39,8 @@ namespace dynamic_programming {
39
39
namespace knapsack {
40
40
/* *
41
41
* @brief Picking up all those items whose combined weight is below
42
- * the given capacity and calculating the value of those picked items. Trying all
43
- * possible combinations will yield the maximum knapsack value.
42
+ * the given capacity and calculating the value of those picked items. Trying
43
+ * all possible combinations will yield the maximum knapsack value.
44
44
* @tparam n size of the weight and value array
45
45
* @param capacity capacity of the carrying bag
46
46
* @param weight array representing the weight of items
@@ -62,9 +62,9 @@ int maxKnapsackValue(const int capacity, const std::array<int, n> &weight,
62
62
// will be zero
63
63
maxValue[i][j] = 0 ;
64
64
} else if (weight[i - 1 ] <= j) {
65
- // if the ith item's weight(in the actual array it will be at i-1)
66
- // is less than or equal to the allowed weight i.e. j then we
67
- // can pick that item for our knapsack. maxValue will be the
65
+ // if the ith item's weight(in the actual array it will be at
66
+ // i-1) is less than or equal to the allowed weight i.e. j then
67
+ // we can pick that item for our knapsack. maxValue will be the
68
68
// obtained either by picking the current item or by not picking
69
69
// current item
70
70
@@ -76,8 +76,9 @@ int maxKnapsackValue(const int capacity, const std::array<int, n> &weight,
76
76
77
77
maxValue[i][j] = std::max (profit1, profit2);
78
78
} else {
79
- // as the weight of the current item is greater than the allowed weight, so
80
- // maxProfit will be profit obtained by excluding the current item.
79
+ // as the weight of the current item is greater than the allowed
80
+ // weight, so maxProfit will be profit obtained by excluding the
81
+ // current item.
81
82
maxValue[i][j] = maxValue[i - 1 ][j];
82
83
}
83
84
}
0 commit comments