This commit is contained in:
krahets 2023-07-14 02:56:32 +08:00
parent e91e3d828c
commit 1c4dbac484
91 changed files with 4129 additions and 202 deletions

View file

@ -1823,7 +1823,7 @@
<li class="md-nav__item">
<a href="/chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1896,6 +1896,8 @@
@ -2003,6 +2005,20 @@
<li class="md-nav__item">
<a href="/chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1907,6 +1907,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结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/edit_distance_problem/">
<link rel="prev" href="../../chapter_dynamic_programming/summary/">
<link rel="next" href="../contribution/">
@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1907,6 +1907,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2469,7 +2485,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../../chapter_dynamic_programming/edit_distance_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 13.6. &amp;nbsp; 编辑距离问题New" rel="prev">
<a href="../../chapter_dynamic_programming/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 13.7. &amp;nbsp; 小结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>
@ -2478,7 +2494,7 @@
上一页
</span>
<div class="md-ellipsis">
13.6. &nbsp; 编辑距离问题New
13.7. &nbsp; 小结New
</div>
</div>
</a>

View file

@ -1898,7 +1898,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1971,6 +1971,8 @@
@ -2078,6 +2080,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1898,7 +1898,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1971,6 +1971,8 @@
@ -2078,6 +2080,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1912,7 +1912,7 @@
<li class="md-nav__item">
<a href="../subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1985,6 +1985,8 @@
@ -2092,6 +2094,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2775,7 +2791,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../subset_sum_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 12.3. &amp;nbsp; 子集和问题New" rel="prev">
<a href="../subset_sum_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 12.3. &amp;nbsp; 子集和问题" 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>
@ -2784,7 +2800,7 @@
上一页
</span>
<div class="md-ellipsis">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</div>
</div>
</a>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -3022,13 +3038,13 @@
<a href="../subset_sum_problem/" class="md-footer__link md-footer__link--next" aria-label="下一页: 12.3. &amp;nbsp; 子集和问题New" rel="next">
<a href="../subset_sum_problem/" class="md-footer__link md-footer__link--next" aria-label="下一页: 12.3. &amp;nbsp; 子集和问题" rel="next">
<div class="md-footer__title">
<span class="md-footer__direction">
下一页
</span>
<div class="md-ellipsis">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -25,7 +25,7 @@
<title>12.3.   子集和问题New - Hello 算法</title>
<title>12.3.   子集和问题 - Hello 算法</title>
@ -113,7 +113,7 @@
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</span>
</div>
@ -1845,12 +1845,12 @@
<label class="md-nav__link md-nav__link--active" for="__toc">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1911,7 +1911,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1984,6 +1984,8 @@
@ -2091,6 +2093,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1939,7 +1939,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -2012,6 +2012,8 @@
@ -2119,6 +2121,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1987,7 +1987,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -2060,6 +2060,8 @@
@ -2167,6 +2169,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1846,7 +1846,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1905,7 +1905,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1978,6 +1978,8 @@
@ -2085,6 +2087,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2264,9 +2280,8 @@
<div class="arithmatex">\[
dp[i] = \min(dp[i-1], dp[i-2]) + cost[i]
\]</div>
<p>这便可以引出「最优子结构」的含义:<strong>原问题的最优解是从子问题的最优解构建得来的</strong>。对于本题,我们从两个子问题最优解 <span class="arithmatex">\(dp[i-1]\)</span> , <span class="arithmatex">\(dp[i-2]\)</span> 中挑选出较优的那一个,并用它构建出原问题 <span class="arithmatex">\(dp[i]\)</span> 的最优解。</p>
<p>相较于分治问题,动态规划问题的解也是由其子问题的解构成的。不同的是,<strong>动态规划中子问题的解不仅揭示了问题的局部最优解,而且还通过特定的递推关系链接起来,共同构建出原问题的全局最优解</strong></p>
<p>那么,上节的爬楼梯题目有没有最优子结构呢?它要求解的是方案数量,看似是一个计数问题,但如果换一种问法:求解最大方案数量。我们意外地发现,<strong>虽然题目修改前后是等价的,但最优子结构浮现出来了</strong>:第 <span class="arithmatex">\(n\)</span> 阶最大方案数量等于第 <span class="arithmatex">\(n-1\)</span> 阶和第 <span class="arithmatex">\(n-2\)</span> 阶最大方案数量之和。所以说,最优子结构的是一个比较宽泛的概念,在不同问题中会有不同的含义。</p>
<p>这便可以引出「最优子结构」的含义:<strong>原问题的最优解是从子问题的最优解构建得来的</strong>。本题显然具有最优子结构:我们从两个子问题最优解 <span class="arithmatex">\(dp[i-1]\)</span> , <span class="arithmatex">\(dp[i-2]\)</span> 中挑选出较优的那一个,并用它构建出原问题 <span class="arithmatex">\(dp[i]\)</span> 的最优解。</p>
<p>那么,上节的爬楼梯题目有没有最优子结构呢?它要求解的是方案数量,看似是一个计数问题,但如果换一种问法:求解最大方案数量。我们意外地发现,<strong>虽然题目修改前后是等价的,但最优子结构浮现出来了</strong>:第 <span class="arithmatex">\(n\)</span> 阶最大方案数量等于第 <span class="arithmatex">\(n-1\)</span> 阶和第 <span class="arithmatex">\(n-2\)</span> 阶最大方案数量之和。所以说,最优子结构的解释方式比较灵活,在不同问题中会有不同的含义。</p>
<p>根据以上状态转移方程,以及初始状态 <span class="arithmatex">\(dp[1] = cost[1]\)</span> , <span class="arithmatex">\(dp[2] = cost[2]\)</span> ,我们可以得出动态规划解题代码。</p>
<div class="tabbed-set tabbed-alternate" data-tabs="1:11"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><input id="__tabbed_1_11" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Java</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Python</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">JavaScript</label><label for="__tabbed_1_6">TypeScript</label><label for="__tabbed_1_7">C</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">Swift</label><label for="__tabbed_1_10">Zig</label><label for="__tabbed_1_11">Dart</label></div>
<div class="tabbed-content">
@ -2620,7 +2635,7 @@ dp[i, 2] = dp[i-2, 1] + dp[i-2, 2]
<p>给定一个共有 <span class="arithmatex">\(n\)</span> 阶的楼梯,你每步可以上 <span class="arithmatex">\(1\)</span> 阶或者 <span class="arithmatex">\(2\)</span> 阶。<strong>规定当爬到第 <span class="arithmatex">\(i\)</span> 阶时,系统自动会给第 <span class="arithmatex">\(2i\)</span> 阶上放上障碍物,之后所有轮都不允许跳到第 <span class="arithmatex">\(2i\)</span> 阶上</strong>。例如,前两轮分别跳到了第 <span class="arithmatex">\(2, 3\)</span> 阶上,则之后就不能跳到第 <span class="arithmatex">\(4, 6\)</span> 阶上。请问有多少种方案可以爬到楼顶。</p>
</div>
<p>在这个问题中,下次跳跃依赖于过去所有的状态,因为每一次跳跃都会在更高的阶梯上设置障碍,并影响未来的跳跃。对于这类问题,动态规划往往难以解决,或是因为计算复杂度过高而难以应用。</p>
<p>实际上,许多组合优化问题(例如著名的旅行商问题)都不满足无后效性。对于这类问题,我们通常会选择使用其他方法,例如启发式搜索、遗传算法、强化学习等,从而降低时间复杂度,在有限时间内得到能够接受的局部最优解。</p>
<p>实际上,许多复杂的组合优化问题(例如著名的旅行商问题)都不满足无后效性。对于这类问题,我们通常会选择使用其他方法,例如启发式搜索、遗传算法、强化学习等,从而降低时间复杂度,在有限时间内得到能够接受的局部最优解。</p>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2085,6 +2087,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../unbounded_knapsack_problem/">
<link rel="next" href="../../chapter_appendix/installation/">
<link rel="next" href="../summary/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.1.11">
@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2210,13 +2226,13 @@
<li><span class="arithmatex">\(s[n-1]\)</span><span class="arithmatex">\(t[m-1]\)</span> 相同,我们可以直接跳过它们,接下来考虑 <span class="arithmatex">\(s[n-2]\)</span><span class="arithmatex">\(t[m-2]\)</span> ;</li>
<li><span class="arithmatex">\(s[n-1]\)</span><span class="arithmatex">\(t[m-1]\)</span> 不同,我们需要对 <span class="arithmatex">\(s\)</span> 进行一次编辑(插入、删除、替换),使得两字符串尾部的字符相同,从而可以跳过它们,考虑规模更小的问题;</li>
</ul>
<p>也就是说,我们在字符串 <span class="arithmatex">\(s\)</span> 中进行的每一轮决策(编辑操作),都会使得 <span class="arithmatex">\(s\)</span><span class="arithmatex">\(t\)</span> 中剩余的待匹配字符发生变化。因此,状态定义为当前在 <span class="arithmatex">\(s\)</span> , <span class="arithmatex">\(t\)</span> 中考虑的第 <span class="arithmatex">\(i\)</span> , <span class="arithmatex">\(j\)</span> 个字符,记为 <span class="arithmatex">\([i, j]\)</span></p>
<p>也就是说,我们在字符串 <span class="arithmatex">\(s\)</span> 中进行的每一轮决策(编辑操作),都会使得 <span class="arithmatex">\(s\)</span><span class="arithmatex">\(t\)</span> 中剩余的待匹配字符发生变化。因此,状态为当前在 <span class="arithmatex">\(s\)</span> , <span class="arithmatex">\(t\)</span> 中考虑的第 <span class="arithmatex">\(i\)</span> , <span class="arithmatex">\(j\)</span> 个字符,记为 <span class="arithmatex">\([i, j]\)</span></p>
<p>状态 <span class="arithmatex">\([i, j]\)</span> 对应的子问题:<strong><span class="arithmatex">\(s\)</span> 的前 <span class="arithmatex">\(i\)</span> 个字符更改为 <span class="arithmatex">\(t\)</span> 的前 <span class="arithmatex">\(j\)</span> 个字符所需的最少编辑步数</strong></p>
<p>至此得到一个尺寸为 <span class="arithmatex">\((i+1) \times (j+1)\)</span> 的二维 <span class="arithmatex">\(dp\)</span> 表。</p>
<p><strong>第二步:找出最优子结构,进而推导出状态转移方程</strong></p>
<p>考虑子问题 <span class="arithmatex">\(dp[i, j]\)</span> ,其对应的两个字符串的尾部字符为 <span class="arithmatex">\(s[i-1]\)</span><span class="arithmatex">\(t[j-1]\)</span> ,可根据不同编辑操作分为三种情况:</p>
<ol>
<li><span class="arithmatex">\(s\)</span> 尾部添加 <span class="arithmatex">\(t[j-1]\)</span> ,则剩余子问题 <span class="arithmatex">\(dp[i, j-1]\)</span> </li>
<li><span class="arithmatex">\(s[i-1]\)</span> 之后添加 <span class="arithmatex">\(t[j-1]\)</span> ,则剩余子问题 <span class="arithmatex">\(dp[i, j-1]\)</span> </li>
<li>删除 <span class="arithmatex">\(s[i-1]\)</span> ,则剩余子问题 <span class="arithmatex">\(dp[i-1, j]\)</span> </li>
<li><span class="arithmatex">\(s[i-1]\)</span> 替换为 <span class="arithmatex">\(t[j-1]\)</span> ,则剩余子问题 <span class="arithmatex">\(dp[i-1, j-1]\)</span> </li>
</ol>
@ -2617,13 +2633,13 @@ dp[i, j] = dp[i-1, j-1]
<a href="../../chapter_appendix/installation/" class="md-footer__link md-footer__link--next" aria-label="下一页: 14.1. &amp;nbsp; 编程环境安装" rel="next">
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 13.7. &amp;nbsp; 小结New" rel="next">
<div class="md-footer__title">
<span class="md-footer__direction">
下一页
</span>
<div class="md-ellipsis">
14.1. &nbsp; 编程环境安装
13.7. &nbsp; 小结New
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2439,7 +2455,8 @@ dp[i] = dp[i-1] + dp[i-2]
<p align="center"> Fig. 方案数量递推关系 </p>
<p>也就是说,在爬楼梯问题中,<strong>各个子问题之间不是相互独立的,原问题的解可以由子问题的解构成</strong></p>
<p>我们可以基于此递推公式写出暴力搜索代码:以 <span class="arithmatex">\(dp[n]\)</span> 为起始点,<strong>从顶至底地将一个较大问题拆解为两个较小问题的和</strong>,直至到达最小子问题 <span class="arithmatex">\(dp[1]\)</span><span class="arithmatex">\(dp[2]\)</span> 时返回。其中,最小子问题的解 <span class="arithmatex">\(dp[1] = 1\)</span> , <span class="arithmatex">\(dp[2] = 2\)</span> 是已知的,代表爬到第 <span class="arithmatex">\(1\)</span> , <span class="arithmatex">\(2\)</span> 阶分别有 <span class="arithmatex">\(1\)</span> , <span class="arithmatex">\(2\)</span> 种方案。</p>
<p>我们可以基于此递推公式写出暴力搜索代码:以 <span class="arithmatex">\(dp[n]\)</span> 为起始点,<strong>从顶至底地将一个较大问题拆解为两个较小问题的和</strong>,直至到达最小子问题 <span class="arithmatex">\(dp[1]\)</span><span class="arithmatex">\(dp[2]\)</span> 时返回。</p>
<p>请注意,最小子问题的解 <span class="arithmatex">\(dp[1] = 1\)</span> , <span class="arithmatex">\(dp[2] = 2\)</span> 是已知的,代表爬到第 <span class="arithmatex">\(1\)</span> , <span class="arithmatex">\(2\)</span> 阶分别有 <span class="arithmatex">\(1\)</span> , <span class="arithmatex">\(2\)</span> 种方案。</p>
<p>观察以下代码,它和标准回溯代码都属于深度优先搜索,但更加简洁。</p>
<div class="tabbed-set tabbed-alternate" data-tabs="2:11"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><input id="__tabbed_2_3" name="__tabbed_2" type="radio" /><input id="__tabbed_2_4" name="__tabbed_2" type="radio" /><input id="__tabbed_2_5" name="__tabbed_2" type="radio" /><input id="__tabbed_2_6" name="__tabbed_2" type="radio" /><input id="__tabbed_2_7" name="__tabbed_2" type="radio" /><input id="__tabbed_2_8" name="__tabbed_2" type="radio" /><input id="__tabbed_2_9" name="__tabbed_2" type="radio" /><input id="__tabbed_2_10" name="__tabbed_2" type="radio" /><input id="__tabbed_2_11" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Java</label><label for="__tabbed_2_2">C++</label><label for="__tabbed_2_3">Python</label><label for="__tabbed_2_4">Go</label><label for="__tabbed_2_5">JavaScript</label><label for="__tabbed_2_6">TypeScript</label><label for="__tabbed_2_7">C</label><label for="__tabbed_2_8">C#</label><label for="__tabbed_2_9">Swift</label><label for="__tabbed_2_10">Zig</label><label for="__tabbed_2_11">Dart</label></div>
<div class="tabbed-content">
@ -2914,7 +2931,7 @@ dp[i] = dp[i-1] + dp[i-2]
</div>
</div>
<p><strong>我们将这种空间优化技巧称为「状态压缩」</strong>。在许多动态规划问题中,当前状态仅与前面有限个状态有关,不必保存所有的历史状态,这时我们可以应用状态压缩,只保留必要的状态,通过“降维”来节省内存空间。</p>
<p>总的看来,子问题分解是一种通用的算法思路,在分治算法、动态规划、回溯算法中各有特点:</p>
<p>总的看来,<strong>子问题分解是一种通用的算法思路,在分治、动态规划、回溯中各有特点</strong></p>
<ul>
<li>分治算法将原问题划分为几个独立的子问题,然后递归解决子问题,最后合并子问题的解得到原问题的解。例如,归并排序将长数组不断划分为两个短子数组,再将排序好的子数组合并为排序好的长数组。</li>
<li>动态规划也是将原问题分解为多个子问题,但与分治算法的主要区别是,<strong>动态规划中的子问题往往不是相互独立的</strong>,原问题的解依赖于子问题的解,而子问题的解又依赖于更小的子问题的解。因此,动态规划通常会引入记忆化,保存已经解决的子问题的解,避免重复计算。</li>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2711,7 +2727,7 @@ dp[i, c] = \max(dp[i-1, c], dp[i-1, c - wgt[i-1]] + val[i-1])
</div>
</div>
<p><strong>最后考虑状态压缩</strong>。以上代码中的数组 <code>dp</code> 占用 <span class="arithmatex">\(O(n \times cap)\)</span> 空间。由于每个状态都只与其上一行的状态有关,因此我们可以使用两个数组滚动前进,将空间复杂度从 <span class="arithmatex">\(O(n^2)\)</span> 将低至 <span class="arithmatex">\(O(n)\)</span> 。代码省略,有兴趣的同学可以自行实现。</p>
<p>那么,我们是否可以仅用一个数组实现状态压缩呢?观察可知,每个状态都是由左上方或正上方的格子转移过来的。假设只有一个数组,当遍历到第 <span class="arithmatex">\(i\)</span> 行时,该数组存储的仍然是第 <span class="arithmatex">\(i-1\)</span> 行的状态,<strong>为了避免左方区域的格子在状态转移中被覆盖,应该采取倒序遍历</strong></p>
<p>那么,我们是否可以仅用一个数组实现状态压缩呢?观察可知,每个状态都是由正上方或左上方的格子转移过来的。假设只有一个数组,当遍历到第 <span class="arithmatex">\(i\)</span> 行时,该数组存储的仍然是第 <span class="arithmatex">\(i-1\)</span> 行的状态,<strong>为了避免左方区域的格子在状态转移中被覆盖,应该采取倒序遍历</strong></p>
<p>以下动画展示了在单个数组下从第 <span class="arithmatex">\(i=1\)</span> 行转换至第 <span class="arithmatex">\(i=2\)</span> 行的过程。建议你思考一下正序遍历和倒序遍历的区别。</p>
<div class="tabbed-set tabbed-alternate" data-tabs="5:6"><input checked="checked" id="__tabbed_5_1" name="__tabbed_5" type="radio" /><input id="__tabbed_5_2" name="__tabbed_5" type="radio" /><input id="__tabbed_5_3" name="__tabbed_5" type="radio" /><input id="__tabbed_5_4" name="__tabbed_5" type="radio" /><input id="__tabbed_5_5" name="__tabbed_5" type="radio" /><input id="__tabbed_5_6" name="__tabbed_5" type="radio" /><div class="tabbed-labels"><label for="__tabbed_5_1">&lt;1&gt;</label><label for="__tabbed_5_2">&lt;2&gt;</label><label for="__tabbed_5_3">&lt;3&gt;</label><label for="__tabbed_5_4">&lt;4&gt;</label><label for="__tabbed_5_5">&lt;5&gt;</label><label for="__tabbed_5_6">&lt;6&gt;</label></div>
<div class="tabbed-content">

File diff suppressed because it is too large Load diff

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>
@ -2367,7 +2383,25 @@ dp[i, c] = \max(dp[i-1, c], dp[i, c - wgt[i-1]] + val[i-1])
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">unbounded_knapsack.cs</span><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">unbounded_knapsack</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">unboundedKnapsackDP</span><span class="p">}</span>
<div class="highlight"><span class="filename">unbounded_knapsack.cs</span><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="cm">/* 完全背包:动态规划 */</span>
<a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">unboundedKnapsackDP</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">wgt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">cap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-7-3" name="__codelineno-7-3" href="#__codelineno-7-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">wgt</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-7-4" name="__codelineno-7-4" href="#__codelineno-7-4"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-7-5" name="__codelineno-7-5" href="#__codelineno-7-5"></a><span class="w"> </span><span class="kt">int</span><span class="p">[,]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">n</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">cap</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-7-6" name="__codelineno-7-6" href="#__codelineno-7-6"></a><span class="w"> </span><span class="c1">// 状态转移</span>
<a id="__codelineno-7-7" name="__codelineno-7-7" href="#__codelineno-7-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-7-8" name="__codelineno-7-8" href="#__codelineno-7-8"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">cap</span><span class="p">;</span><span class="w"> </span><span class="n">c</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-7-9" name="__codelineno-7-9" href="#__codelineno-7-9"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">wgt</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">c</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-7-10" name="__codelineno-7-10" href="#__codelineno-7-10"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选物品 i</span>
<a id="__codelineno-7-11" name="__codelineno-7-11" href="#__codelineno-7-11"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="p">];</span>
<a id="__codelineno-7-12" name="__codelineno-7-12" href="#__codelineno-7-12"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-7-13" name="__codelineno-7-13" href="#__codelineno-7-13"></a><span class="w"> </span><span class="c1">// 不选和选物品 i 这两种方案的较大值</span>
<a id="__codelineno-7-14" name="__codelineno-7-14" href="#__codelineno-7-14"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Math</span><span class="p">.</span><span class="n">Max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="p">],</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">wgt</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">val</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]);</span>
<a id="__codelineno-7-15" name="__codelineno-7-15" href="#__codelineno-7-15"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-7-16" name="__codelineno-7-16" href="#__codelineno-7-16"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-7-17" name="__codelineno-7-17" href="#__codelineno-7-17"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-7-18" name="__codelineno-7-18" href="#__codelineno-7-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">cap</span><span class="p">];</span>
<a id="__codelineno-7-19" name="__codelineno-7-19" href="#__codelineno-7-19"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">
@ -2490,7 +2524,25 @@ dp[i, c] = \max(dp[i-1, c], dp[i, c - wgt[i-1]] + val[i-1])
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">unbounded_knapsack.cs</span><pre><span></span><code><a id="__codelineno-18-1" name="__codelineno-18-1" href="#__codelineno-18-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">unbounded_knapsack</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">unboundedKnapsackDPComp</span><span class="p">}</span>
<div class="highlight"><span class="filename">unbounded_knapsack.cs</span><pre><span></span><code><a id="__codelineno-18-1" name="__codelineno-18-1" href="#__codelineno-18-1"></a><span class="cm">/* 完全背包:状态压缩后的动态规划 */</span>
<a id="__codelineno-18-2" name="__codelineno-18-2" href="#__codelineno-18-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">unboundedKnapsackDPComp</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">wgt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">cap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-18-3" name="__codelineno-18-3" href="#__codelineno-18-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">wgt</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-18-4" name="__codelineno-18-4" href="#__codelineno-18-4"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-18-5" name="__codelineno-18-5" href="#__codelineno-18-5"></a><span class="w"> </span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">cap</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-18-6" name="__codelineno-18-6" href="#__codelineno-18-6"></a><span class="w"> </span><span class="c1">// 状态转移</span>
<a id="__codelineno-18-7" name="__codelineno-18-7" href="#__codelineno-18-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-18-8" name="__codelineno-18-8" href="#__codelineno-18-8"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">cap</span><span class="p">;</span><span class="w"> </span><span class="n">c</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-18-9" name="__codelineno-18-9" href="#__codelineno-18-9"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">wgt</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">c</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-18-10" name="__codelineno-18-10" href="#__codelineno-18-10"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选物品 i</span>
<a id="__codelineno-18-11" name="__codelineno-18-11" href="#__codelineno-18-11"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">c</span><span class="p">];</span>
<a id="__codelineno-18-12" name="__codelineno-18-12" href="#__codelineno-18-12"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-18-13" name="__codelineno-18-13" href="#__codelineno-18-13"></a><span class="w"> </span><span class="c1">// 不选和选物品 i 这两种方案的较大值</span>
<a id="__codelineno-18-14" name="__codelineno-18-14" href="#__codelineno-18-14"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Math</span><span class="p">.</span><span class="n">Max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">c</span><span class="p">],</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">c</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">wgt</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">val</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]);</span>
<a id="__codelineno-18-15" name="__codelineno-18-15" href="#__codelineno-18-15"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-18-16" name="__codelineno-18-16" href="#__codelineno-18-16"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-18-17" name="__codelineno-18-17" href="#__codelineno-18-17"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-18-18" name="__codelineno-18-18" href="#__codelineno-18-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">cap</span><span class="p">];</span>
<a id="__codelineno-18-19" name="__codelineno-18-19" href="#__codelineno-18-19"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">
@ -2635,7 +2687,30 @@ dp[i, a] = \min(dp[i-1, a], dp[i, a - coins[i-1]] + 1)
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">coin_change.cs</span><pre><span></span><code><a id="__codelineno-29-1" name="__codelineno-29-1" href="#__codelineno-29-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">coin_change</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">coinChangeDP</span><span class="p">}</span>
<div class="highlight"><span class="filename">coin_change.cs</span><pre><span></span><code><a id="__codelineno-29-1" name="__codelineno-29-1" href="#__codelineno-29-1"></a><span class="cm">/* 零钱兑换:动态规划 */</span>
<a id="__codelineno-29-2" name="__codelineno-29-2" href="#__codelineno-29-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">coinChangeDP</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">coins</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-3" name="__codelineno-29-3" href="#__codelineno-29-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coins</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-29-4" name="__codelineno-29-4" href="#__codelineno-29-4"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">MAX</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-29-5" name="__codelineno-29-5" href="#__codelineno-29-5"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-29-6" name="__codelineno-29-6" href="#__codelineno-29-6"></a><span class="w"> </span><span class="kt">int</span><span class="p">[,]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">n</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-29-7" name="__codelineno-29-7" href="#__codelineno-29-7"></a><span class="w"> </span><span class="c1">// 状态转移:首行首列</span>
<a id="__codelineno-29-8" name="__codelineno-29-8" href="#__codelineno-29-8"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">amt</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-9" name="__codelineno-29-9" href="#__codelineno-29-9"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MAX</span><span class="p">;</span>
<a id="__codelineno-29-10" name="__codelineno-29-10" href="#__codelineno-29-10"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-29-11" name="__codelineno-29-11" href="#__codelineno-29-11"></a><span class="w"> </span><span class="c1">// 状态转移:其余行列</span>
<a id="__codelineno-29-12" name="__codelineno-29-12" href="#__codelineno-29-12"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-13" name="__codelineno-29-13" href="#__codelineno-29-13"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">amt</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-14" name="__codelineno-29-14" href="#__codelineno-29-14"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-15" name="__codelineno-29-15" href="#__codelineno-29-15"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选硬币 i</span>
<a id="__codelineno-29-16" name="__codelineno-29-16" href="#__codelineno-29-16"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">];</span>
<a id="__codelineno-29-17" name="__codelineno-29-17" href="#__codelineno-29-17"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-29-18" name="__codelineno-29-18" href="#__codelineno-29-18"></a><span class="w"> </span><span class="c1">// 不选和选硬币 i 这两种方案的较小值</span>
<a id="__codelineno-29-19" name="__codelineno-29-19" href="#__codelineno-29-19"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Math</span><span class="p">.</span><span class="n">Min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">],</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">);</span>
<a id="__codelineno-29-20" name="__codelineno-29-20" href="#__codelineno-29-20"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-29-21" name="__codelineno-29-21" href="#__codelineno-29-21"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-29-22" name="__codelineno-29-22" href="#__codelineno-29-22"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-29-23" name="__codelineno-29-23" href="#__codelineno-29-23"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">amt</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">MAX</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">amt</span><span class="p">]</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="o">-</span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-29-24" name="__codelineno-29-24" href="#__codelineno-29-24"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">
@ -2792,7 +2867,28 @@ dp[i, a] = \min(dp[i-1, a], dp[i, a - coins[i-1]] + 1)
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">coin_change.cs</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">coin_change</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">coinChangeDPComp</span><span class="p">}</span>
<div class="highlight"><span class="filename">coin_change.cs</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="cm">/* 零钱兑换:状态压缩后的动态规划 */</span>
<a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">coinChangeDPComp</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">coins</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coins</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-40-4" name="__codelineno-40-4" href="#__codelineno-40-4"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">MAX</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-40-5" name="__codelineno-40-5" href="#__codelineno-40-5"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-40-6" name="__codelineno-40-6" href="#__codelineno-40-6"></a><span class="w"> </span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-40-7" name="__codelineno-40-7" href="#__codelineno-40-7"></a><span class="w"> </span><span class="n">Array</span><span class="p">.</span><span class="n">Fill</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span><span class="w"> </span><span class="n">MAX</span><span class="p">);</span>
<a id="__codelineno-40-8" name="__codelineno-40-8" href="#__codelineno-40-8"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="m">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">;</span>
<a id="__codelineno-40-9" name="__codelineno-40-9" href="#__codelineno-40-9"></a><span class="w"> </span><span class="c1">// 状态转移</span>
<a id="__codelineno-40-10" name="__codelineno-40-10" href="#__codelineno-40-10"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-40-11" name="__codelineno-40-11" href="#__codelineno-40-11"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">amt</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-40-12" name="__codelineno-40-12" href="#__codelineno-40-12"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-40-13" name="__codelineno-40-13" href="#__codelineno-40-13"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选硬币 i</span>
<a id="__codelineno-40-14" name="__codelineno-40-14" href="#__codelineno-40-14"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">];</span>
<a id="__codelineno-40-15" name="__codelineno-40-15" href="#__codelineno-40-15"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-40-16" name="__codelineno-40-16" href="#__codelineno-40-16"></a><span class="w"> </span><span class="c1">// 不选和选硬币 i 这两种方案的较小值</span>
<a id="__codelineno-40-17" name="__codelineno-40-17" href="#__codelineno-40-17"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Math</span><span class="p">.</span><span class="n">Min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">],</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">);</span>
<a id="__codelineno-40-18" name="__codelineno-40-18" href="#__codelineno-40-18"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-40-19" name="__codelineno-40-19" href="#__codelineno-40-19"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-40-20" name="__codelineno-40-20" href="#__codelineno-40-20"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-40-21" name="__codelineno-40-21" href="#__codelineno-40-21"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">amt</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">MAX</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">amt</span><span class="p">]</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="o">-</span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-40-22" name="__codelineno-40-22" href="#__codelineno-40-22"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">
@ -2915,7 +3011,29 @@ dp[i, a] = dp[i-1, a] + dp[i, a - coins[i-1]]
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">coin_change_ii.cs</span><pre><span></span><code><a id="__codelineno-51-1" name="__codelineno-51-1" href="#__codelineno-51-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">coin_change_ii</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">coinChangeIIDP</span><span class="p">}</span>
<div class="highlight"><span class="filename">coin_change_ii.cs</span><pre><span></span><code><a id="__codelineno-51-1" name="__codelineno-51-1" href="#__codelineno-51-1"></a><span class="cm">/* 零钱兑换 II动态规划 */</span>
<a id="__codelineno-51-2" name="__codelineno-51-2" href="#__codelineno-51-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">coinChangeIIDP</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">coins</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-3" name="__codelineno-51-3" href="#__codelineno-51-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coins</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-51-4" name="__codelineno-51-4" href="#__codelineno-51-4"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-51-5" name="__codelineno-51-5" href="#__codelineno-51-5"></a><span class="w"> </span><span class="kt">int</span><span class="p">[,]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">n</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-51-6" name="__codelineno-51-6" href="#__codelineno-51-6"></a><span class="w"> </span><span class="c1">// 初始化首列</span>
<a id="__codelineno-51-7" name="__codelineno-51-7" href="#__codelineno-51-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-8" name="__codelineno-51-8" href="#__codelineno-51-8"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-51-9" name="__codelineno-51-9" href="#__codelineno-51-9"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-51-10" name="__codelineno-51-10" href="#__codelineno-51-10"></a><span class="w"> </span><span class="c1">// 状态转移</span>
<a id="__codelineno-51-11" name="__codelineno-51-11" href="#__codelineno-51-11"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-12" name="__codelineno-51-12" href="#__codelineno-51-12"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">amt</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-13" name="__codelineno-51-13" href="#__codelineno-51-13"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-14" name="__codelineno-51-14" href="#__codelineno-51-14"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选硬币 i</span>
<a id="__codelineno-51-15" name="__codelineno-51-15" href="#__codelineno-51-15"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">];</span>
<a id="__codelineno-51-16" name="__codelineno-51-16" href="#__codelineno-51-16"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-51-17" name="__codelineno-51-17" href="#__codelineno-51-17"></a><span class="w"> </span><span class="c1">// 不选和选硬币 i 这两种方案之和</span>
<a id="__codelineno-51-18" name="__codelineno-51-18" href="#__codelineno-51-18"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]];</span>
<a id="__codelineno-51-19" name="__codelineno-51-19" href="#__codelineno-51-19"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-51-20" name="__codelineno-51-20" href="#__codelineno-51-20"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-51-21" name="__codelineno-51-21" href="#__codelineno-51-21"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-51-22" name="__codelineno-51-22" href="#__codelineno-51-22"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">amt</span><span class="p">];</span>
<a id="__codelineno-51-23" name="__codelineno-51-23" href="#__codelineno-51-23"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">
@ -3018,7 +3136,26 @@ dp[i, a] = dp[i-1, a] + dp[i, a - coins[i-1]]
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><span class="filename">coin_change_ii.cs</span><pre><span></span><code><a id="__codelineno-62-1" name="__codelineno-62-1" href="#__codelineno-62-1"></a><span class="na">[class]</span><span class="p">{</span><span class="n">coin_change_ii</span><span class="p">}</span><span class="o">-</span><span class="p">[</span><span class="n">func</span><span class="p">]{</span><span class="n">coinChangeIIDPComp</span><span class="p">}</span>
<div class="highlight"><span class="filename">coin_change_ii.cs</span><pre><span></span><code><a id="__codelineno-62-1" name="__codelineno-62-1" href="#__codelineno-62-1"></a><span class="cm">/* 零钱兑换 II状态压缩后的动态规划 */</span>
<a id="__codelineno-62-2" name="__codelineno-62-2" href="#__codelineno-62-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">coinChangeIIDPComp</span><span class="p">(</span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">coins</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">amt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-62-3" name="__codelineno-62-3" href="#__codelineno-62-3"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coins</span><span class="p">.</span><span class="n">Length</span><span class="p">;</span>
<a id="__codelineno-62-4" name="__codelineno-62-4" href="#__codelineno-62-4"></a><span class="w"> </span><span class="c1">// 初始化 dp 表</span>
<a id="__codelineno-62-5" name="__codelineno-62-5" href="#__codelineno-62-5"></a><span class="w"> </span><span class="kt">int</span><span class="p">[]</span><span class="w"> </span><span class="n">dp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="n">amt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">];</span>
<a id="__codelineno-62-6" name="__codelineno-62-6" href="#__codelineno-62-6"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="m">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>
<a id="__codelineno-62-7" name="__codelineno-62-7" href="#__codelineno-62-7"></a><span class="w"> </span><span class="c1">// 状态转移</span>
<a id="__codelineno-62-8" name="__codelineno-62-8" href="#__codelineno-62-8"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-62-9" name="__codelineno-62-9" href="#__codelineno-62-9"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">amt</span><span class="p">;</span><span class="w"> </span><span class="n">a</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-62-10" name="__codelineno-62-10" href="#__codelineno-62-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-62-11" name="__codelineno-62-11" href="#__codelineno-62-11"></a><span class="w"> </span><span class="c1">// 若超过背包容量,则不选硬币 i</span>
<a id="__codelineno-62-12" name="__codelineno-62-12" href="#__codelineno-62-12"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">];</span>
<a id="__codelineno-62-13" name="__codelineno-62-13" href="#__codelineno-62-13"></a><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-62-14" name="__codelineno-62-14" href="#__codelineno-62-14"></a><span class="w"> </span><span class="c1">// 不选和选硬币 i 这两种方案之和</span>
<a id="__codelineno-62-15" name="__codelineno-62-15" href="#__codelineno-62-15"></a><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">a</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">coins</span><span class="p">[</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">]];</span>
<a id="__codelineno-62-16" name="__codelineno-62-16" href="#__codelineno-62-16"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-62-17" name="__codelineno-62-17" href="#__codelineno-62-17"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-62-18" name="__codelineno-62-18" href="#__codelineno-62-18"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-62-19" name="__codelineno-62-19" href="#__codelineno-62-19"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">dp</span><span class="p">[</span><span class="n">amt</span><span class="p">];</span>
<a id="__codelineno-62-20" name="__codelineno-62-20" href="#__codelineno-62-20"></a><span class="p">}</span>
</code></pre></div>
</div>
<div class="tabbed-block">

View file

@ -1918,7 +1918,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1991,6 +1991,8 @@
@ -2098,6 +2100,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1924,7 +1924,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1997,6 +1997,8 @@
@ -2104,6 +2106,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1898,7 +1898,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1971,6 +1971,8 @@
@ -2078,6 +2080,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1904,7 +1904,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1977,6 +1977,8 @@
@ -2084,6 +2086,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1925,7 +1925,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1998,6 +1998,8 @@
@ -2105,6 +2107,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1846,7 +1846,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1846,7 +1846,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1834,7 +1834,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1907,6 +1907,8 @@
@ -2014,6 +2016,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1905,7 +1905,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1978,6 +1978,8 @@
@ -2085,6 +2087,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1846,7 +1846,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1832,7 +1832,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1905,6 +1905,8 @@
@ -2012,6 +2014,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1846,7 +1846,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1919,6 +1919,8 @@
@ -2026,6 +2028,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1898,7 +1898,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1971,6 +1971,8 @@
@ -2078,6 +2080,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1905,7 +1905,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1978,6 +1978,8 @@
@ -2085,6 +2087,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1884,7 +1884,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1957,6 +1957,8 @@
@ -2064,6 +2066,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1911,7 +1911,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1984,6 +1984,8 @@
@ -2091,6 +2093,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1911,7 +1911,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1984,6 +1984,8 @@
@ -2091,6 +2093,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1945,7 +1945,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -2018,6 +2018,8 @@
@ -2125,6 +2127,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1891,7 +1891,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1964,6 +1964,8 @@
@ -2071,6 +2073,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1986,7 +1986,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -2059,6 +2059,8 @@
@ -2166,6 +2168,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1925,7 +1925,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1998,6 +1998,8 @@
@ -2105,6 +2107,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1932,7 +1932,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -2005,6 +2005,8 @@
@ -2112,6 +2114,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1924,7 +1924,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1997,6 +1997,8 @@
@ -2104,6 +2106,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1836,7 +1836,7 @@
<li class="md-nav__item">
<a href="../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1909,6 +1909,8 @@
@ -2016,6 +2018,20 @@
<li class="md-nav__item">
<a href="../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1877,7 +1877,7 @@
<li class="md-nav__item">
<a href="../../chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1950,6 +1950,8 @@
@ -2057,6 +2059,20 @@
<li class="md-nav__item">
<a href="../../chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

View file

@ -1827,7 +1827,7 @@
<li class="md-nav__item">
<a href="chapter_backtracking/subset_sum_problem/" class="md-nav__link">
12.3. &nbsp; 子集和问题New
12.3. &nbsp; 子集和问题
</a>
</li>
@ -1900,6 +1900,8 @@
@ -2007,6 +2009,20 @@
<li class="md-nav__item">
<a href="chapter_dynamic_programming/summary/" class="md-nav__link">
13.7. &nbsp; 小结New
</a>
</li>
</ul>
</nav>
</li>

File diff suppressed because one or more lines are too long

View file

@ -2,432 +2,437 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.hello-algo.com/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_appendix/contribution/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_appendix/installation/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/array/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/list/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/backtracking_algorithm/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/n_queens_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/permutations_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/subset_sum_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_backtracking/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_computational_complexity/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_computational_complexity/space_complexity/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_computational_complexity/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_computational_complexity/time_complexity/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/basic_data_types/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/character_encoding/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/number_encoding/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_data_structure/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_problem_features/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_solution_pipeline/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/edit_distance_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/intro_to_dynamic_programming/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/knapsack_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/summary/</loc>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_dynamic_programming/unbounded_knapsack_problem/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/graph/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/graph_operations/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/graph_traversal/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/hash_algorithm/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/hash_collision/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/hash_map/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/build_heap/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/heap/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/top_k/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/what_is_dsa/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_preface/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_preface/about_the_book/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_preface/suggestions/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_preface/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_reference/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/binary_search/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/binary_search_edge/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/replace_linear_by_hashing/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/searching_algorithm_revisited/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_searching/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/bubble_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/bucket_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/counting_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/heap_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/insertion_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/merge_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/quick_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/radix_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/selection_sort/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/sorting_algorithm/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_sorting/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_stack_and_queue/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_stack_and_queue/deque/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_stack_and_queue/queue/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_stack_and_queue/stack/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_stack_and_queue/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/array_representation_of_tree/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/avl_tree/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/binary_search_tree/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/binary_tree/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/binary_tree_traversal/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_tree/summary/</loc>
<lastmod>2023-07-12</lastmod>
<lastmod>2023-07-13</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>

Binary file not shown.