This commit is contained in:
krahets 2023-07-06 00:08:29 +08:00
parent e3fc609eb9
commit e8bd56ea08
110 changed files with 4197 additions and 99 deletions

View file

@ -1889,6 +1889,8 @@
@ -1939,6 +1941,20 @@
<li class="md-nav__item">
<a href="/chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1900,6 +1900,8 @@
@ -1950,6 +1952,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -15,7 +15,7 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_appendix/installation/">
<link rel="prev" href="../../chapter_dynamic_programming/dp_problem_features/">
<link rel="prev" href="../../chapter_dynamic_programming/knapsack_problem/">
<link rel="next" href="../contribution/">
@ -1900,6 +1900,8 @@
@ -1950,6 +1952,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -2405,7 +2421,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../../chapter_dynamic_programming/dp_problem_features/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 13.2. &amp;nbsp; DP 问题特性New" rel="prev">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 13.3. &amp;nbsp; 0-1 背包问题New" rel="prev">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</div>
@ -2414,7 +2430,7 @@
上一页
</span>
<div class="md-ellipsis">
13.2. &nbsp; DP 问题特性New
13.3. &nbsp; 0-1 背包问题New
</div>
</div>
</a>

View file

@ -1964,6 +1964,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1964,6 +1964,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1978,6 +1978,8 @@
@ -2028,6 +2030,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1977,6 +1977,8 @@
@ -2027,6 +2029,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -2005,6 +2005,8 @@
@ -2055,6 +2057,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -2053,6 +2053,8 @@
@ -2103,6 +2105,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1971,6 +1971,8 @@
@ -2021,6 +2023,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../intro_to_dynamic_programming/">
<link rel="next" href="../../chapter_appendix/installation/">
<link rel="next" href="../knapsack_problem/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.1.11">
@ -1902,6 +1902,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -2650,13 +2666,13 @@ dp[i, 2] = dp[i-2, 1] + dp[i-2, 2]
<a href="../../chapter_appendix/installation/" class="md-footer__link md-footer__link--next" aria-label="下一页: 14.1. &amp;nbsp; 编程环境安装" rel="next">
<a href="../knapsack_problem/" class="md-footer__link md-footer__link--next" aria-label="下一页: 13.3. &amp;nbsp; 0-1 背包问题New" rel="next">
<div class="md-footer__title">
<span class="md-footer__direction">
下一页
</span>
<div class="md-ellipsis">
14.1. &nbsp; 编程环境安装
13.3. &nbsp; 0-1 背包问题New
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

File diff suppressed because it is too large Load diff

View file

@ -1984,6 +1984,8 @@
@ -2034,6 +2036,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -3326,8 +3342,8 @@
<a id="__codelineno-14-43" name="__codelineno-14-43" href="#__codelineno-14-43"></a><span class="w"> </span><span class="nb">panic</span><span class="p">(</span><span class="s">&quot;error&quot;</span><span class="p">)</span>
<a id="__codelineno-14-44" name="__codelineno-14-44" href="#__codelineno-14-44"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-14-45" name="__codelineno-14-45" href="#__codelineno-14-45"></a><span class="w"> </span><span class="c1">// 删除边 vet1 - vet2</span>
<a id="__codelineno-14-46" name="__codelineno-14-46" href="#__codelineno-14-46"></a><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet1</span><span class="p">],</span><span class="w"> </span><span class="nx">vet2</span><span class="p">)</span>
<a id="__codelineno-14-47" name="__codelineno-14-47" href="#__codelineno-14-47"></a><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet2</span><span class="p">],</span><span class="w"> </span><span class="nx">vet1</span><span class="p">)</span>
<a id="__codelineno-14-46" name="__codelineno-14-46" href="#__codelineno-14-46"></a><span class="w"> </span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet1</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet1</span><span class="p">],</span><span class="w"> </span><span class="nx">vet2</span><span class="p">)</span>
<a id="__codelineno-14-47" name="__codelineno-14-47" href="#__codelineno-14-47"></a><span class="w"> </span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet2</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">vet2</span><span class="p">],</span><span class="w"> </span><span class="nx">vet1</span><span class="p">)</span>
<a id="__codelineno-14-48" name="__codelineno-14-48" href="#__codelineno-14-48"></a><span class="p">}</span>
<a id="__codelineno-14-49" name="__codelineno-14-49" href="#__codelineno-14-49"></a>
<a id="__codelineno-14-50" name="__codelineno-14-50" href="#__codelineno-14-50"></a><span class="cm">/* 添加顶点 */</span>
@ -3349,8 +3365,8 @@
<a id="__codelineno-14-66" name="__codelineno-14-66" href="#__codelineno-14-66"></a><span class="w"> </span><span class="c1">// 在邻接表中删除顶点 vet 对应的链表</span>
<a id="__codelineno-14-67" name="__codelineno-14-67" href="#__codelineno-14-67"></a><span class="w"> </span><span class="nb">delete</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">,</span><span class="w"> </span><span class="nx">vet</span><span class="p">)</span>
<a id="__codelineno-14-68" name="__codelineno-14-68" href="#__codelineno-14-68"></a><span class="w"> </span><span class="c1">// 遍历其他顶点的链表,删除所有包含 vet 的边</span>
<a id="__codelineno-14-69" name="__codelineno-14-69" href="#__codelineno-14-69"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">_</span><span class="p">,</span><span class="w"> </span><span class="nx">list</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-14-70" name="__codelineno-14-70" href="#__codelineno-14-70"></a><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">list</span><span class="p">,</span><span class="w"> </span><span class="nx">vet</span><span class="p">)</span>
<a id="__codelineno-14-69" name="__codelineno-14-69" href="#__codelineno-14-69"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">v</span><span class="p">,</span><span class="w"> </span><span class="nx">list</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-14-70" name="__codelineno-14-70" href="#__codelineno-14-70"></a><span class="w"> </span><span class="nx">g</span><span class="p">.</span><span class="nx">adjList</span><span class="p">[</span><span class="nx">v</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="nx">DeleteSliceElms</span><span class="p">(</span><span class="nx">list</span><span class="p">,</span><span class="w"> </span><span class="nx">vet</span><span class="p">)</span>
<a id="__codelineno-14-71" name="__codelineno-14-71" href="#__codelineno-14-71"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-14-72" name="__codelineno-14-72" href="#__codelineno-14-72"></a><span class="p">}</span>
<a id="__codelineno-14-73" name="__codelineno-14-73" href="#__codelineno-14-73"></a>

View file

@ -1990,6 +1990,8 @@
@ -2040,6 +2042,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1964,6 +1964,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1970,6 +1970,8 @@
@ -2020,6 +2022,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -2203,11 +2219,11 @@
<p><img alt="哈希表的抽象表示" src="../hash_map.assets/hash_table_lookup.png" /></p>
<p align="center"> Fig. 哈希表的抽象表示 </p>
<p>除哈希表外,我们还可以使用数组或链表实现查询功能,其中</p>
<p>除哈希表外,我们还可以使用数组或链表实现查询功能。若将学生数据看作数组(链表)元素,则有</p>
<ul>
<li>查询元素需要遍历数组(链表)中的所有元素,使用 <span class="arithmatex">\(O(n)\)</span> 时间;</li>
<li>添加元素仅需添加至数组(链表)的尾部即可,使用 <span class="arithmatex">\(O(1)\)</span> 时间;</li>
<li>删除元素需要先查询再删除,使用 <span class="arithmatex">\(O(n)\)</span> 时间;</li>
<li><strong>添加元素</strong>:仅需将元素添加至数组(链表)的尾部即可,使用 <span class="arithmatex">\(O(1)\)</span> 时间;</li>
<li><strong>查询元素</strong>:由于数组(链表)是乱序的,因此需要遍历数组(链表)中的所有元素,使用 <span class="arithmatex">\(O(n)\)</span> 时间;</li>
<li><strong>删除元素</strong>需要先查询到元素,从数组中删除,使用 <span class="arithmatex">\(O(n)\)</span> 时间;</li>
</ul>
<div class="center-table">
<table>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1991,6 +1991,8 @@
@ -2041,6 +2043,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -2125,7 +2141,7 @@
<h1 id="11">1.1. &nbsp; 算法无处不在<a class="headerlink" href="#11" title="Permanent link">&para;</a></h1>
<p>当我们听到“算法”这个词时,很自然地会想到数学。然而实际上,许多算法并不涉及复杂数学,而是更多地依赖于基本逻辑,这些逻辑在我们的日常生活中处处可见。</p>
<p>在正式探讨算法之前,有一个有趣的事实值得分享:<strong>你已经在不知不觉中学会了许多算法,并习惯将它们应用到日常生活中了</strong>。下面,我将举个具体例子来证实这一点。</p>
<p>在正式探讨算法之前,有一个有趣的事实值得分享:<strong>你已经在不知不觉中学会了许多算法,并习惯将它们应用到日常生活中了</strong>。下面,我将举个具体例子来证实这一点。</p>
<p><strong>例一:拼装积木</strong>。一套积木,除了包含许多零件之外,还附有详细的组装说明书。我们按照说明书一步步操作,就能组装出精美的积木模型。</p>
<p>从数据结构与算法的角度来看,积木的各种形状和连接方式代表数据结构,而组装说明书上的一系列步骤则是算法。</p>
<p><img alt="拼装积木" src="../algorithms_are_everywhere.assets/assembling_blocks.jpg" /></p>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1900,6 +1900,8 @@
@ -1950,6 +1952,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1971,6 +1971,8 @@
@ -2021,6 +2023,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1898,6 +1898,8 @@
@ -1948,6 +1950,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,6 +1912,8 @@
@ -1962,6 +1964,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>
@ -2283,7 +2299,7 @@
<a id="__codelineno-2-9" name="__codelineno-2-9" href="#__codelineno-2-9"></a> <span class="n">i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="n">k</span><span class="p">)</span>
<a id="__codelineno-2-10" name="__codelineno-2-10" href="#__codelineno-2-10"></a> <span class="c1"># 将 num 添加进桶 i</span>
<a id="__codelineno-2-11" name="__codelineno-2-11" href="#__codelineno-2-11"></a> <span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
<a id="__codelineno-2-12" name="__codelineno-2-12" href="#__codelineno-2-12"></a> <span class="c1"># 2. 对各个桶执行排序5</span>
<a id="__codelineno-2-12" name="__codelineno-2-12" href="#__codelineno-2-12"></a> <span class="c1"># 2. 对各个桶执行排序</span>
<a id="__codelineno-2-13" name="__codelineno-2-13" href="#__codelineno-2-13"></a> <span class="k">for</span> <span class="n">bucket</span> <span class="ow">in</span> <span class="n">buckets</span><span class="p">:</span>
<a id="__codelineno-2-14" name="__codelineno-2-14" href="#__codelineno-2-14"></a> <span class="c1"># 使用内置排序函数,也可以替换成其他排序算法</span>
<a id="__codelineno-2-15" name="__codelineno-2-15" href="#__codelineno-2-15"></a> <span class="n">bucket</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>

View file

@ -1964,6 +1964,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1971,6 +1971,8 @@
@ -2021,6 +2023,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1950,6 +1950,8 @@
@ -2000,6 +2002,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1977,6 +1977,8 @@
@ -2027,6 +2029,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1902,6 +1902,8 @@
@ -1952,6 +1954,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1977,6 +1977,8 @@
@ -2027,6 +2029,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -2011,6 +2011,8 @@
@ -2061,6 +2063,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1943,6 +1943,8 @@
@ -1993,6 +1995,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1957,6 +1957,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/knapsack_problem/" class="md-nav__link">
13.3. &nbsp; 0-1 背包问题New
</a>
</li>
</ul>
</nav>
</li>

Some files were not shown because too many files have changed in this diff Show more