mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-22 04:42:10 +08:00
Documentation for ee9835378f
This commit is contained in:
@@ -130,10 +130,10 @@ Namespaces</h2></td></tr>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:a15edf30f336885e5b851f6b7199c6cd1"><td class="memTemplParams" colspan="2">template<size_t n> </td></tr>
|
||||
<tr class="memitem:a15edf30f336885e5b851f6b7199c6cd1"><td class="memTemplItemLeft" align="right" valign="top">int </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">dynamic_programming::knapsack::maxKnapsackValue</a> (const int capacity, const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< int, n > &weight, const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/array.html">std::array</a>< int, n > &value)</td></tr>
|
||||
<tr class="memdesc:a15edf30f336885e5b851f6b7199c6cd1"><td class="mdescLeft"> </td><td class="mdescRight">Picking up all those items whose combined weight is below given capacity and calculating value of those picked items.Trying all possible combinations will yield the maximum knapsack value. <a href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a15edf30f336885e5b851f6b7199c6cd1"><td class="mdescLeft"> </td><td class="mdescRight">Picking up all those items whose combined weight is below the given capacity and calculating the value of those picked items. Trying all possible combinations will yield the maximum knapsack value. <a href="../../db/d16/0__1__knapsack_8cpp.html#a15edf30f336885e5b851f6b7199c6cd1">More...</a><br /></td></tr>
|
||||
<tr class="separator:a15edf30f336885e5b851f6b7199c6cd1"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Function to test above algorithm. <a href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Function to test the above algorithm. <a href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
||||
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d16/0__1__knapsack_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
||||
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../db/d16/0__1__knapsack_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
||||
@@ -172,7 +172,7 @@ Algorithm</h3>
|
||||
<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 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 the 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>
|
||||
<div class="dyncontent">
|
||||
@@ -216,7 +216,7 @@ template<size_t n> </div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Picking up all those items whose combined weight is below given capacity and calculating value of those picked items.Trying all possible combinations will yield the maximum knapsack value. </p>
|
||||
<p>Picking up all those items whose combined weight is below the given capacity and calculating the value of those picked items. Trying all possible combinations will yield the maximum knapsack value. </p>
|
||||
<dl class="tparams"><dt>Template Parameters</dt><dd>
|
||||
<table class="tparams">
|
||||
<tr><td class="paramname">n</td><td>size of the weight and value array </td></tr>
|
||||
@@ -226,17 +226,17 @@ template<size_t n> </div>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">capacity</td><td>capacity of the carrying bag </td></tr>
|
||||
<tr><td class="paramname">weight</td><td>array representing weight of items </td></tr>
|
||||
<tr><td class="paramname">value</td><td>array representing value of items </td></tr>
|
||||
<tr><td class="paramname">weight</td><td>array representing the weight of items </td></tr>
|
||||
<tr><td class="paramname">value</td><td>array representing the value of items </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>maximum value obtainable with given capacity. </dd></dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>maximum value obtainable with a given capacity. </dd></dl>
|
||||
<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<std::vector<int></a> > 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<int></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"> 56</span> <span class="comment">// inner loop will select the capacity of the 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 < 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 < capacity + 1; ++j) {</div>
|
||||
@@ -245,22 +245,22 @@ template<size_t n> </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] <= j) {</div>
|
||||
<div class="line"><span class="lineno"> 65</span> <span class="comment">// if the ith item's weight(in actual array it will be at i-1)</span></div>
|
||||
<div class="line"><span class="lineno"> 65</span> <span class="comment">// if the ith item's weight(in the 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"> 71</span> <span class="comment">// picking the 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"> 74</span> <span class="comment">// not picking the 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"> 79</span> <span class="comment">// as the weight of the current item is greater than the allowed weight, so</span></div>
|
||||
<div class="line"><span class="lineno"> 80</span> <span class="comment">// maxProfit will be profit obtained by excluding the 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>
|
||||
@@ -303,7 +303,7 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Function to test above algorithm. </p>
|
||||
<p>Function to test the above algorithm. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
||||
<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>
|
||||
@@ -330,7 +330,7 @@ Here is the call graph for this function:</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> << <span class="stringliteral">"Maximum Knapsack value with "</span> << n2 << <span class="stringliteral">" items is "</span></div>
|
||||
<div class="line"><span class="lineno"> 119</span> << max_value2 << <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< int, n > &weight, const std::array< int, n > &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="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< int, n > &weight, const std::array< int, n > &value)</div><div class="ttdoc">Picking up all those items whose combined weight is below the given capacity and calculating the valu...</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>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
|
||||
@@ -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,69"/>
|
||||
<area shape="rect" id="node1" title="Picking up all those items whose combined weight is below the given capacity and calculating the valu..." alt="" coords="5,29,215,69"/>
|
||||
<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,62"/>
|
||||
</map>
|
||||
|
||||
@@ -1 +1 @@
|
||||
724ed1407e50869dde170dd42b6d573e
|
||||
f139929d34c31e39ac08d10326fb2779
|
||||
@@ -11,7 +11,7 @@
|
||||
<!-- Node1 -->
|
||||
<g id="node1" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_node1"><a xlink:title="Picking up all those items whose combined weight is below given capacity and calculating value of tho...">
|
||||
<g id="a_node1"><a xlink:title="Picking up all those items whose combined weight is below the given capacity and calculating the valu...">
|
||||
<polygon fill="#999999" stroke="#666666" points="157,-30 0,-30 0,0 157,0 157,-30"/>
|
||||
<text text-anchor="start" x="8" y="-18" font-family="Helvetica,sans-Serif" font-size="10.00">dynamic_programming</text>
|
||||
<text text-anchor="middle" x="78.5" y="-7" font-family="Helvetica,sans-Serif" font-size="10.00">::knapsack::maxKnapsackValue</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -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,31"/>
|
||||
<area shape="rect" id="node1" title="Function to test the above algorithm." alt="" coords="5,5,49,31"/>
|
||||
<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,31"/>
|
||||
</map>
|
||||
|
||||
@@ -1 +1 @@
|
||||
46b6febb5b5840bc7a05d9ec95c6ba32
|
||||
5f681fb811530ee5c7eb42a5d7253788
|
||||
@@ -11,7 +11,7 @@
|
||||
<!-- Node1 -->
|
||||
<g id="node1" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_node1"><a xlink:title="Function to test above algorithm.">
|
||||
<g id="a_node1"><a xlink:title="Function to test the above algorithm.">
|
||||
<polygon fill="#999999" stroke="#666666" points="33,-19 0,-19 0,0 33,0 33,-19"/>
|
||||
<text text-anchor="middle" x="16.5" y="-7" font-family="Helvetica,sans-Serif" font-size="10.00">test</text>
|
||||
</a>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -1,5 +1,5 @@
|
||||
<map id="main" name="main">
|
||||
<area shape="rect" id="node1" title="Main function." alt="" coords="5,5,56,31"/>
|
||||
<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,31"/>
|
||||
<area shape="rect" id="node2" href="$db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" title="Function to test the above algorithm." alt="" coords="104,5,148,31"/>
|
||||
<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,31"/>
|
||||
</map>
|
||||
|
||||
@@ -1 +1 @@
|
||||
ce0c49ee8db22c9cca13a98a2d46cfb0
|
||||
949bae17c94477d71c596af699efcd98
|
||||
@@ -20,7 +20,7 @@
|
||||
<!-- Node2 -->
|
||||
<g id="node2" class="node">
|
||||
<title>Node2</title>
|
||||
<g id="a_node2"><a xlink:href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" target="_top" xlink:title="Function to test above algorithm.">
|
||||
<g id="a_node2"><a xlink:href="../../db/d16/0__1__knapsack_8cpp.html#aa8dca7b867074164d5f45b0f3851269d" target="_top" xlink:title="Function to test the above algorithm.">
|
||||
<polygon fill="white" stroke="#666666" points="107,-19 74,-19 74,0 107,0 107,-19"/>
|
||||
<text text-anchor="middle" x="90.5" y="-7" font-family="Helvetica,sans-Serif" font-size="10.00">test</text>
|
||||
</a>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user