This commit is contained in:
krahets 2023-07-21 22:50:40 +08:00
parent 1188810504
commit 739eb755ca
103 changed files with 3165 additions and 15 deletions

View file

@ -2889,6 +2889,8 @@
@ -3050,6 +3052,34 @@
<li class="md-nav__item">
<a href="/chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2900,6 +2900,8 @@
@ -3061,6 +3063,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -15,7 +15,7 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_appendix/">
<link rel="prev" href="../chapter_greedy/max_product_cutting_problem/">
<link rel="prev" href="../chapter_greedy/summary/">
<link rel="next" href="installation/">
@ -2900,6 +2900,8 @@
@ -3061,6 +3063,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>
@ -3366,7 +3396,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../chapter_greedy/max_product_cutting_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 15.4. &amp;nbsp; 最大切分乘积问题" rel="prev">
<a href="../chapter_greedy/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 15.5. &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>
@ -3376,7 +3406,7 @@
上一页
</span>
<div class="md-ellipsis">
15.4. &nbsp; 最大切分乘积问题
15.5. &nbsp; 小结
</div>
</div>
</a>

View file

@ -2900,6 +2900,8 @@
@ -3061,6 +3063,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2970,6 +2970,8 @@
@ -3131,6 +3133,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2977,6 +2977,8 @@
@ -3138,6 +3140,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2984,6 +2984,8 @@
@ -3145,6 +3147,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2970,6 +2970,8 @@
@ -3131,6 +3133,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3003,6 +3003,8 @@
@ -3164,6 +3166,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3003,6 +3003,8 @@
@ -3164,6 +3166,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2983,6 +2983,8 @@
@ -3144,6 +3146,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3011,6 +3011,8 @@
@ -3172,6 +3174,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3059,6 +3059,8 @@
@ -3220,6 +3222,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2977,6 +2977,8 @@
@ -3138,6 +3140,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2964,6 +2964,8 @@
@ -3125,6 +3127,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2978,6 +2978,8 @@
@ -3139,6 +3141,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2991,6 +2991,8 @@
@ -3152,6 +3154,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2971,6 +2971,8 @@
@ -3132,6 +3134,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2964,6 +2964,8 @@
@ -3125,6 +3127,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2998,6 +2998,8 @@
@ -3159,6 +3161,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2964,6 +2964,8 @@
@ -3125,6 +3127,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2978,6 +2978,8 @@
@ -3139,6 +3141,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2978,6 +2978,8 @@
@ -3139,6 +3141,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3031,6 +3031,8 @@
@ -3192,6 +3194,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2990,6 +2990,8 @@
@ -3151,6 +3153,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2996,6 +2996,8 @@
@ -3157,6 +3159,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3132,6 +3134,34 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3139,6 +3141,34 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>
@ -3391,7 +3421,6 @@
<p class="admonition-title">Question</p>
<p>给定 <span class="arithmatex">\(n\)</span> 种硬币,第 <span class="arithmatex">\(i\)</span> 个硬币的面值为 <span class="arithmatex">\(coins[i - 1]\)</span> ,目标金额为 <span class="arithmatex">\(amt\)</span> ,每种硬币可以重复选取,问能够凑出目标金额的最少硬币个数。如果无法凑出目标金额则返回 <span class="arithmatex">\(-1\)</span></p>
</div>
<p>贪心算法会迭代地做出一个又一个的贪心选择,每轮都将问题转化成一个规模更小的子问题,直到问题被解决。</p>
<p>这道题的贪心策略在生活中很常见:给定目标金额,<strong>我们贪心地选择不大于且最接近它的硬币</strong>,不断循环该步骤,直至凑出目标金额为止。</p>
<p><img alt="零钱兑换的贪心策略" src="../greedy_algorithm.assets/coin_change_greedy_strategy.png" /></p>
<p align="center"> Fig. 零钱兑换的贪心策略 </p>
@ -3512,7 +3541,7 @@
</ol>
<h2 id="1512">15.1.2. &nbsp; 贪心算法特性<a class="headerlink" href="#1512" title="Permanent link">&para;</a></h2>
<p>那么问题来了,什么样的问题适合用贪心算法求解呢?或者说,贪心算法在什么情况下可以保证找到最优解?</p>
<p>相较于动态规划,贪心算法的使用条件更加苛刻,其主要关问题的两个性质:</p>
<p>相较于动态规划,贪心算法的使用条件更加苛刻,其主要关问题的两个性质:</p>
<ul>
<li><strong>贪心选择性质</strong>:只有当局部最优选择始终可以导致全局最优解时,贪心算法才能保证得到最优解。</li>
<li><strong>最优子结构</strong>:原问题的最优解包含子问题的最优解。值得注意的是,一些问题的最优子结构并不明显,但仍然可使用贪心算法解决。</li>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>
@ -3292,6 +3322,7 @@
<li><a href="https://www.hello-algo.com/chapter_greedy/fractional_knapsack_problem/">15.2 &nbsp; 分数背包问题</a></li>
<li><a href="https://www.hello-algo.com/chapter_greedy/max_capacity_problem/">15.3 &nbsp; 最大容量问题</a></li>
<li><a href="https://www.hello-algo.com/chapter_greedy/max_product_cutting_problem/">15.4 &nbsp; 最大切分乘积问题</a></li>
<li><a href="https://www.hello-algo.com/chapter_greedy/summary/">15.5 &nbsp; 小结</a></li>
</ul>

View file

@ -2902,6 +2902,8 @@
@ -3132,6 +3134,34 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../max_capacity_problem/">
<link rel="next" href="../../chapter_appendix/">
<link rel="next" href="../summary/">
<link rel="icon" href="../../assets/images/favicon.png">
@ -2902,6 +2902,8 @@
@ -3132,6 +3134,34 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>
@ -3626,13 +3656,13 @@ n = 3 a + b
<a href="../../chapter_appendix/" class="md-footer__link md-footer__link--next" aria-label="下一页: 16. &amp;nbsp; 附录" rel="next">
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 15.5. &amp;nbsp; 小结" rel="next">
<div class="md-footer__title">
<span class="md-footer__direction">
下一页
</span>
<div class="md-ellipsis">
16. &nbsp; 附录
15.5. &nbsp; 小结
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -15,6 +15,10 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_greedy/summary/">
<link rel="prev" href="../max_product_cutting_problem/">
<link rel="next" href="../../chapter_appendix/">
<link rel="icon" href="../../assets/images/favicon.png">
@ -22,7 +26,7 @@
<title>Summary - Hello 算法</title>
<title>15.5.   小结 - Hello 算法</title>
@ -77,6 +81,11 @@
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#155" class="md-skip">
跳转至
</a>
</div>
<div data-md-component="announce">
@ -108,7 +117,7 @@
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Summary
15.5. &nbsp; 小结
</span>
</div>
@ -2894,13 +2903,17 @@
<li class="md-nav__item md-nav__item--nested">
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_16" >
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_16" checked>
@ -2931,7 +2944,7 @@
</div>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_16_label" aria-expanded="false">
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_16_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_16">
<span class="md-nav__icon md-icon"></span>
15. &nbsp; 贪心
@ -3052,6 +3065,44 @@
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>
@ -3233,6 +3284,8 @@
</nav>
</div>
</div>
@ -3254,13 +3307,72 @@
<h1>Summary</h1>
<h1 id="155">15.5. &nbsp; 小结<a class="headerlink" href="#155" title="Permanent link">&para;</a></h1>
<ul>
<li>贪心算法通常用于解决最优化问题,其原理是在每个决策阶段都做出局部最优的决策,以期望获得全局最优解。</li>
<li>贪心算法会迭代地做出一个又一个的贪心选择,每轮都将问题转化成一个规模更小的子问题,直到问题被解决。</li>
<li>贪心算法不仅实现简单,还具有很高的解题效率。相比于动态规划,贪心算法的时间复杂度通常低一个数量级。</li>
<li>在零钱兑换问题中,对于某些硬币组合,贪心算法可以保证找到最优解;对于另外一些硬币组合则不然,贪心算法可能找到很差的解。</li>
<li>贪心问题具有两大性质:贪心选择性质和最优子结构。贪心选择性质代表贪心策略的有效性。</li>
<li>对于某些复杂问题,贪心选择性质的证明并不简单。相对来说,证伪更加容易,例如零钱兑换问题。</li>
<li>求解贪心问题主要分为三步:问题分析、贪心策略确定、正确性证明。其中,贪心策略确定是核心步骤,而正确性证明是难点。</li>
<li>分数背包问题在 0-1 背包的基础上,允许选择物品的一部分,因此可使用贪心算法求解。可以采用反证法证明贪心策略的正确性。</li>
<li>最大容量问题可使用穷举法求解,时间复杂度为 <span class="arithmatex">\(O(n^2)\)</span> 。通过设计贪心策略,每轮向内移动短板,可将时间复杂度优化至 <span class="arithmatex">\(O(n)\)</span></li>
<li>在最大切分乘积问题中,我们先后推理出两个贪心策略:<span class="arithmatex">\(\geq 4\)</span> 的整数都应该继续切分、最优切分因子为 <span class="arithmatex">\(3\)</span> ,从而得到贪心解法。代码中包含幂运算,时间复杂度取决于幂运算实现方法,通常为 <span class="arithmatex">\(O(1)\)</span><span class="arithmatex">\(O(\log n)\)</span></li>
</ul>
<h2 id="__comments">评论</h2>
<!-- Insert generated snippet here -->
<script
src="https://giscus.app/client.js"
data-repo="krahets/hello-algo"
data-repo-id="R_kgDOIXtSqw"
data-category="Announcements"
data-category-id="DIC_kwDOIXtSq84CSZk_"
data-mapping="pathname"
data-strict="1"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="top"
data-theme="preferred_color_scheme"
data-lang="zh-CN"
crossorigin="anonymous"
async
>
</script>
<!-- Synchronize Giscus theme with palette -->
<script>
var giscus = document.querySelector("script[src*=giscus]")
/* Set palette on initial load */
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light"
giscus.setAttribute("data-theme", theme)
}
/* Register event handlers after documented loaded */
document.addEventListener("DOMContentLoaded", function() {
var ref = document.querySelector("[data-md-component=palette]")
ref.addEventListener("change", function() {
var palette = __md_get("__palette")
if (palette && typeof palette.color === "object") {
var theme = palette.color.scheme === "slate" ? "dark" : "light"
/* Instruct Giscus to change theme */
var frame = document.querySelector(".giscus-frame")
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
"https://giscus.app"
)
}
})
})
</script>
</article>
@ -3283,6 +3395,44 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../max_product_cutting_problem/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 15.4. &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>
<div class="md-footer__title">
<span class="md-footer__direction">
上一页
</span>
<div class="md-ellipsis">
15.4. &nbsp; 最大切分乘积问题
</div>
</div>
</a>
<a href="../../chapter_appendix/" class="md-footer__link md-footer__link--next" aria-label="下一页: 16. &amp;nbsp; 附录" rel="next">
<div class="md-footer__title">
<span class="md-footer__direction">
下一页
</span>
<div class="md-ellipsis">
16. &nbsp; 附录
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
</div>
</a>
</nav>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">

View file

@ -2970,6 +2970,8 @@
@ -3131,6 +3133,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2976,6 +2976,8 @@
@ -3137,6 +3139,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2997,6 +2997,8 @@
@ -3158,6 +3160,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2900,6 +2900,8 @@
@ -3061,6 +3063,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2977,6 +2977,8 @@
@ -3138,6 +3140,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2898,6 +2898,8 @@
@ -3059,6 +3061,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2912,6 +2912,8 @@
@ -3073,6 +3075,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2970,6 +2970,8 @@
@ -3131,6 +3133,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2977,6 +2977,8 @@
@ -3138,6 +3140,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2956,6 +2956,8 @@
@ -3117,6 +3119,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2983,6 +2983,8 @@
@ -3144,6 +3146,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2983,6 +2983,8 @@
@ -3144,6 +3146,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3017,6 +3017,8 @@
@ -3178,6 +3180,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2963,6 +2963,8 @@
@ -3124,6 +3126,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3058,6 +3058,8 @@
@ -3219,6 +3221,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2997,6 +2997,8 @@
@ -3158,6 +3160,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -3004,6 +3004,8 @@
@ -3165,6 +3167,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2996,6 +2996,8 @@
@ -3157,6 +3159,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2902,6 +2902,8 @@
@ -3063,6 +3065,34 @@
<li class="md-nav__item">
<a href="../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

View file

@ -2949,6 +2949,8 @@
@ -3110,6 +3112,34 @@
<li class="md-nav__item">
<a href="../../chapter_greedy/summary/" class="md-nav__link">
<span class="md-ellipsis">
15.5. &nbsp; 小结
</span>
<span class="md-status md-status--new" title="最近添加">
</span>
</a>
</li>
</ul>
</nav>

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