Documentation for 53a6c16730

This commit is contained in:
github-actions
2022-01-16 16:05:19 +00:00
parent 778f1be9e5
commit 2cab28c905
3620 changed files with 52045 additions and 41188 deletions

View File

@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="generator" content="Doxygen 1.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: dynamic_programming/0_1_knapsack.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
@@ -30,8 +30,8 @@ MathJax.Hub.Config({
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
@@ -97,7 +97,7 @@ $(document).ready(function(){initNavTree('db/d16/0__1__knapsack_8cpp.html','../.
</div><!--header-->
<div class="contents">
<p>Implementation of <a href="https://en.wikipedia.org/wiki/Knapsack_problem" target="_blank">0-1 Knapsack Problem</a>
<p>Implementation of [0-1 <a class="el" href="../../d7/daf/namespace_knapsack.html" title="Implementation of 0-1 Knapsack problem.">Knapsack</a> Problem] (<a href="https://en.wikipedia.org/wiki/Knapsack_problem">https://en.wikipedia.org/wiki/Knapsack_problem</a>)
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;array&gt;</code><br />
<code>#include &lt;cassert&gt;</code><br />
@@ -133,7 +133,7 @@ Functions</h2></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Implementation of <a href="https://en.wikipedia.org/wiki/Knapsack_problem" target="_blank">0-1 Knapsack Problem</a> </p>
<div class="textblock"><p >Implementation of [0-1 <a class="el" href="../../d7/daf/namespace_knapsack.html" title="Implementation of 0-1 Knapsack problem.">Knapsack</a> Problem] (<a href="https://en.wikipedia.org/wiki/Knapsack_problem">https://en.wikipedia.org/wiki/Knapsack_problem</a>) </p>
<p >Given weights and values of n items, put these items in a knapsack of capacity <code>W</code> to get the maximum total value in the knapsack. In other words, given two integer arrays <code>val[0..n-1]</code> and <code>wt[0..n-1]</code> which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of <code>val[]</code> such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or dont pick it (0-1 property)</p>
<h3><a class="anchor" id="autotoc_md66"></a>
Algorithm</h3>
@@ -160,11 +160,11 @@ Algorithm</h3>
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> {</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> <span class="comment">// Testing</span></div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span>}</div>
<div class="fragment"><div class="line"><span class="lineno"> 126</span> {</div>
<div class="line"><span class="lineno"> 127</span> <span class="comment">// Testing</span></div>
<div class="line"><span class="lineno"> 128</span> <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
<div class="line"><span class="lineno"> 129</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 130</span>}</div>
<div class="ttc" id="a0__1__knapsack_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Function to test above algorithm.</div><div class="ttdef"><b>Definition:</b> 0_1_knapsack.cpp:96</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
@@ -225,43 +225,43 @@ template&lt;size_t n&gt; </div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>maximum value obtainable with given capacity. </dd></dl>
<div class="fragment"><div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> {</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::vector&lt;int&gt;</a> &gt; maxValue(n + 1,</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;int&gt;</a>(capacity + 1, 0));</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="comment">// outer loop will select no of items allowed</span></div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="comment">// inner loop will select capcity of knapsack bag</span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keywordtype">int</span> items = <span class="keyword">sizeof</span>(weight) / <span class="keyword">sizeof</span>(weight[0]);</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; items + 1; ++i) {</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> j = 0; j &lt; capacity + 1; ++j) {</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keywordflow">if</span> (i == 0 || j == 0) {</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="comment">// if no of items is zero or capacity is zero, then maxValue</span></div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <span class="comment">// will be zero</span></div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> maxValue[i][j] = 0;</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (weight[i - 1] &lt;= j) {</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="comment">// if the ith item&#39;s weight(in actual array it will be at i-1)</span></div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="comment">// is less than or equal to the allowed weight i.e. j then we</span></div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <span class="comment">// can pick that item for our knapsack. maxValue will be the</span></div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="comment">// obtained either by picking the current item or by not picking</span></div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="comment">// current item</span></div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> </div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="comment">// picking current item</span></div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <span class="keywordtype">int</span> profit1 = value[i - 1] + maxValue[i - 1][j - weight[i - 1]];</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="comment">// not picking current item</span></div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <span class="keywordtype">int</span> profit2 = maxValue[i - 1][j];</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> </div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> maxValue[i][j] = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a>(profit1, profit2);</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> <span class="comment">// as weight of current item is greater than allowed weight, so</span></div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="comment">// maxProfit will be profit obtained by excluding current item.</span></div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> maxValue[i][j] = maxValue[i - 1][j];</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> }</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> }</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> }</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="comment">// returning maximum value</span></div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <span class="keywordflow">return</span> maxValue[items][capacity];</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span>}</div>
<div class="fragment"><div class="line"><span class="lineno"> 52</span> {</div>
<div class="line"><span class="lineno"> 53</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::vector&lt;int&gt;</a> &gt; maxValue(n + 1,</div>
<div class="line"><span class="lineno"> 54</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;int&gt;</a>(capacity + 1, 0));</div>
<div class="line"><span class="lineno"> 55</span> <span class="comment">// outer loop will select no of items allowed</span></div>
<div class="line"><span class="lineno"> 56</span> <span class="comment">// inner loop will select capcity of knapsack bag</span></div>
<div class="line"><span class="lineno"> 57</span> <span class="keywordtype">int</span> items = <span class="keyword">sizeof</span>(weight) / <span class="keyword">sizeof</span>(weight[0]);</div>
<div class="line"><span class="lineno"> 58</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; items + 1; ++i) {</div>
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> j = 0; j &lt; capacity + 1; ++j) {</div>
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">if</span> (i == 0 || j == 0) {</div>
<div class="line"><span class="lineno"> 61</span> <span class="comment">// if no of items is zero or capacity is zero, then maxValue</span></div>
<div class="line"><span class="lineno"> 62</span> <span class="comment">// will be zero</span></div>
<div class="line"><span class="lineno"> 63</span> maxValue[i][j] = 0;</div>
<div class="line"><span class="lineno"> 64</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (weight[i - 1] &lt;= j) {</div>
<div class="line"><span class="lineno"> 65</span> <span class="comment">// if the ith item&#39;s weight(in actual array it will be at i-1)</span></div>
<div class="line"><span class="lineno"> 66</span> <span class="comment">// is less than or equal to the allowed weight i.e. j then we</span></div>
<div class="line"><span class="lineno"> 67</span> <span class="comment">// can pick that item for our knapsack. maxValue will be the</span></div>
<div class="line"><span class="lineno"> 68</span> <span class="comment">// obtained either by picking the current item or by not picking</span></div>
<div class="line"><span class="lineno"> 69</span> <span class="comment">// current item</span></div>
<div class="line"><span class="lineno"> 70</span> </div>
<div class="line"><span class="lineno"> 71</span> <span class="comment">// picking current item</span></div>
<div class="line"><span class="lineno"> 72</span> <span class="keywordtype">int</span> profit1 = value[i - 1] + maxValue[i - 1][j - weight[i - 1]];</div>
<div class="line"><span class="lineno"> 73</span> </div>
<div class="line"><span class="lineno"> 74</span> <span class="comment">// not picking current item</span></div>
<div class="line"><span class="lineno"> 75</span> <span class="keywordtype">int</span> profit2 = maxValue[i - 1][j];</div>
<div class="line"><span class="lineno"> 76</span> </div>
<div class="line"><span class="lineno"> 77</span> maxValue[i][j] = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a>(profit1, profit2);</div>
<div class="line"><span class="lineno"> 78</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 79</span> <span class="comment">// as weight of current item is greater than allowed weight, so</span></div>
<div class="line"><span class="lineno"> 80</span> <span class="comment">// maxProfit will be profit obtained by excluding current item.</span></div>
<div class="line"><span class="lineno"> 81</span> maxValue[i][j] = maxValue[i - 1][j];</div>
<div class="line"><span class="lineno"> 82</span> }</div>
<div class="line"><span class="lineno"> 83</span> }</div>
<div class="line"><span class="lineno"> 84</span> }</div>
<div class="line"><span class="lineno"> 85</span> </div>
<div class="line"><span class="lineno"> 86</span> <span class="comment">// returning maximum value</span></div>
<div class="line"><span class="lineno"> 87</span> <span class="keywordflow">return</span> maxValue[items][capacity];</div>
<div class="line"><span class="lineno"> 88</span>}</div>
<div class="ttc" id="amax_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a></div><div class="ttdeci">T max(T... args)</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></div></div>
</div><!-- fragment --><div class="dynheader">
@@ -298,31 +298,31 @@ Here is the call graph for this function:</div>
<p>Function to test above algorithm. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> {</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="comment">// Test 1</span></div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> <span class="keyword">const</span> <span class="keywordtype">int</span> n1 = 3; <span class="comment">// number of items</span></div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n1&gt;</a> weight1 = {10, 20, 30}; <span class="comment">// weight of each item</span></div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n1&gt;</a> value1 = {60, 100, 120}; <span class="comment">// value of each item</span></div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> <span class="keyword">const</span> <span class="keywordtype">int</span> capacity1 = 50; <span class="comment">// capacity of carrying bag</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="keyword">const</span> <span class="keywordtype">int</span> max_value1 = <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a>(</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> capacity1, weight1, value1);</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> <span class="keyword">const</span> <span class="keywordtype">int</span> expected_max_value1 = 220;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> assert(max_value1 == expected_max_value1);</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Maximum Knapsack value with &quot;</span> &lt;&lt; n1 &lt;&lt; <span class="stringliteral">&quot; items is &quot;</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> &lt;&lt; max_value1 &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> </div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> <span class="comment">// Test 2</span></div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <span class="keyword">const</span> <span class="keywordtype">int</span> n2 = 4; <span class="comment">// number of items</span></div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n2&gt;</a> weight2 = {24, 10, 10, 7}; <span class="comment">// weight of each item</span></div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n2&gt;</a> value2 = {24, 18, 18, 10}; <span class="comment">// value of each item</span></div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> <span class="keyword">const</span> <span class="keywordtype">int</span> capacity2 = 25; <span class="comment">// capacity of carrying bag</span></div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <span class="keyword">const</span> <span class="keywordtype">int</span> max_value2 = <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a>(</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> capacity2, weight2, value2);</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> <span class="keyword">const</span> <span class="keywordtype">int</span> expected_max_value2 = 36;</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> assert(max_value2 == expected_max_value2);</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Maximum Knapsack value with &quot;</span> &lt;&lt; n2 &lt;&lt; <span class="stringliteral">&quot; items is &quot;</span></div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> &lt;&lt; max_value2 &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span>}</div>
<div class="fragment"><div class="line"><span class="lineno"> 96</span> {</div>
<div class="line"><span class="lineno"> 97</span> <span class="comment">// Test 1</span></div>
<div class="line"><span class="lineno"> 98</span> <span class="keyword">const</span> <span class="keywordtype">int</span> n1 = 3; <span class="comment">// number of items</span></div>
<div class="line"><span class="lineno"> 99</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n1&gt;</a> weight1 = {10, 20, 30}; <span class="comment">// weight of each item</span></div>
<div class="line"><span class="lineno"> 100</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n1&gt;</a> value1 = {60, 100, 120}; <span class="comment">// value of each item</span></div>
<div class="line"><span class="lineno"> 101</span> <span class="keyword">const</span> <span class="keywordtype">int</span> capacity1 = 50; <span class="comment">// capacity of carrying bag</span></div>
<div class="line"><span class="lineno"> 102</span> <span class="keyword">const</span> <span class="keywordtype">int</span> max_value1 = <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a>(</div>
<div class="line"><span class="lineno"> 103</span> capacity1, weight1, value1);</div>
<div class="line"><span class="lineno"> 104</span> <span class="keyword">const</span> <span class="keywordtype">int</span> expected_max_value1 = 220;</div>
<div class="line"><span class="lineno"> 105</span> assert(max_value1 == expected_max_value1);</div>
<div class="line"><span class="lineno"> 106</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Maximum Knapsack value with &quot;</span> &lt;&lt; n1 &lt;&lt; <span class="stringliteral">&quot; items is &quot;</span></div>
<div class="line"><span class="lineno"> 107</span> &lt;&lt; max_value1 &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 108</span> </div>
<div class="line"><span class="lineno"> 109</span> <span class="comment">// Test 2</span></div>
<div class="line"><span class="lineno"> 110</span> <span class="keyword">const</span> <span class="keywordtype">int</span> n2 = 4; <span class="comment">// number of items</span></div>
<div class="line"><span class="lineno"> 111</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n2&gt;</a> weight2 = {24, 10, 10, 7}; <span class="comment">// weight of each item</span></div>
<div class="line"><span class="lineno"> 112</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array&lt;int, n2&gt;</a> value2 = {24, 18, 18, 10}; <span class="comment">// value of each item</span></div>
<div class="line"><span class="lineno"> 113</span> <span class="keyword">const</span> <span class="keywordtype">int</span> capacity2 = 25; <span class="comment">// capacity of carrying bag</span></div>
<div class="line"><span class="lineno"> 114</span> <span class="keyword">const</span> <span class="keywordtype">int</span> max_value2 = <a class="code hl_function" href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a>(</div>
<div class="line"><span class="lineno"> 115</span> capacity2, weight2, value2);</div>
<div class="line"><span class="lineno"> 116</span> <span class="keyword">const</span> <span class="keywordtype">int</span> expected_max_value2 = 36;</div>
<div class="line"><span class="lineno"> 117</span> assert(max_value2 == expected_max_value2);</div>
<div class="line"><span class="lineno"> 118</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Maximum Knapsack value with &quot;</span> &lt;&lt; n2 &lt;&lt; <span class="stringliteral">&quot; items is &quot;</span></div>
<div class="line"><span class="lineno"> 119</span> &lt;&lt; max_value2 &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 120</span>}</div>
<div class="ttc" id="a0__1__knapsack_8cpp_html_a15edf30f336885e5b851f6b7199c6cd1"><div class="ttname"><a href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a></div><div class="ttdeci">int maxKnapsackValue(const int capacity, const std::array&lt; int, n &gt; &amp;weight, const std::array&lt; int, n &gt; &amp;value)</div><div class="ttdoc">Picking up all those items whose combined weight is below given capacity and calculating value of tho...</div><div class="ttdef"><b>Definition:</b> 0_1_knapsack.cpp:51</div></div>
<div class="ttc" id="aarray_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a></div></div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
@@ -342,7 +342,7 @@ Here is the call graph for this function:</div>
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_8a20dd5bfd5341a725342bf72b6b686f.html">dynamic_programming</a></li><li class="navelem"><a class="el" href="../../db/d16/0__1__knapsack_8cpp.html">0_1_knapsack.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
</ul>
</div>
</body>

View File

@@ -1,4 +1,4 @@
<map id="dynamic_programming::knapsack::maxKnapsackValue" name="dynamic_programming::knapsack::maxKnapsackValue">
<area shape="rect" id="node1" title="Picking up all those items whose combined weight is below given capacity and calculating value of tho..." alt="" coords="5,29,215,71"/>
<area shape="rect" id="node2" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/algorithm/max.html#" title=" " alt="" coords="263,37,336,63"/>
<area shape="rect" id="node2" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/algorithm/max#" title=" " alt="" coords="263,37,336,63"/>
</map>

View File

@@ -1 +1 @@
c86f60a494594907b1dcc48d575dc9f8
7b48bda1c0bc6b9b8c47158dc2d11519

View File

@@ -28,7 +28,7 @@
<!-- Node2 -->
<g id="node2" class="node">
<title>Node2</title>
<g id="a_node2"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/max.html#" xlink:title=" ">
<g id="a_node2"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/max#" xlink:title=" ">
<polygon fill="white" stroke="black" points="193,-6 193,-25 248,-25 248,-6 193,-6"/>
<text text-anchor="middle" x="220.5" y="-13" font-family="Helvetica,sans-Serif" font-size="10.00">std::max</text>
</a>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,4 +1,4 @@
<map id="test" name="test">
<area shape="rect" id="node1" title="Function to test above algorithm." alt="" coords="5,5,49,32"/>
<area shape="rect" id="node2" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/io/manip/endl.html#" title=" " alt="" coords="97,5,169,32"/>
<area shape="rect" id="node2" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/io/manip/endl#" title=" " alt="" coords="97,5,169,32"/>
</map>

View File

@@ -1 +1 @@
64c90610e30b3ab35b411975a63245fd
6725c7e36dfa354b77bf80ef690e3c61

View File

@@ -21,7 +21,7 @@
<!-- Node2 -->
<g id="node2" class="node">
<title>Node2</title>
<g id="a_node2"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/io/manip/endl.html#" xlink:title=" ">
<g id="a_node2"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/io/manip/endl#" xlink:title=" ">
<polygon fill="white" stroke="black" points="69,-0.5 69,-19.5 123,-19.5 123,-0.5 69,-0.5"/>
<text text-anchor="middle" x="96" y="-7.5" font-family="Helvetica,sans-Serif" font-size="10.00">std::endl</text>
</a>

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,5 +1,5 @@
<map id="main" name="main">
<area shape="rect" id="node1" title="Main function." alt="" coords="5,5,56,32"/>
<area shape="rect" id="node2" href="$db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" title="Function to test above algorithm." alt="" coords="104,5,148,32"/>
<area shape="rect" id="node3" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/io/manip/endl.html#" title=" " alt="" coords="196,5,268,32"/>
<area shape="rect" id="node3" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/io/manip/endl#" title=" " alt="" coords="196,5,268,32"/>
</map>

View File

@@ -1 +1 @@
9afee202f399d4d5a1866bc1fd0a1124
5197251d9d01fae606e4998b92ce05e7

View File

@@ -36,7 +36,7 @@
<!-- Node3 -->
<g id="node3" class="node">
<title>Node3</title>
<g id="a_node3"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/io/manip/endl.html#" xlink:title=" ">
<g id="a_node3"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/io/manip/endl#" xlink:title=" ">
<polygon fill="white" stroke="black" points="143,-0.5 143,-19.5 197,-19.5 197,-0.5 143,-0.5"/>
<text text-anchor="middle" x="170" y="-7.5" font-family="Helvetica,sans-Serif" font-size="10.00">std::endl</text>
</a>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB