mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-14 03:22:23 +08:00
deploy
This commit is contained in:
@ -1862,7 +1862,8 @@
|
||||
|
||||
<h1 id="123-n">12.3. N 皇后问题<a class="headerlink" href="#123-n" title="Permanent link">¶</a></h1>
|
||||
<div class="admonition question">
|
||||
<p class="admonition-title">根据国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。给定 <span class="arithmatex">\(n\)</span> 个皇后和一个 <span class="arithmatex">\(n \times n\)</span> 大小的棋盘,寻找使得所有皇后之间无法相互攻击的摆放方案。</p>
|
||||
<p class="admonition-title">Question</p>
|
||||
<p>根据国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。给定 <span class="arithmatex">\(n\)</span> 个皇后和一个 <span class="arithmatex">\(n \times n\)</span> 大小的棋盘,寻找使得所有皇后之间无法相互攻击的摆放方案。</p>
|
||||
</div>
|
||||
<p>如下图所示,当 <span class="arithmatex">\(n = 4\)</span> 时,共可以找到两个解。从回溯算法的角度看,<span class="arithmatex">\(n \times n\)</span> 大小的棋盘共有 <span class="arithmatex">\(n^2\)</span> 个格子,给出了所有的选择 <code>choices</code> 。在逐个放置皇后的过程中,棋盘状态在不断地变化,每个时刻的棋盘就是状态 <code>state</code> 。</p>
|
||||
<p><img alt="4 皇后问题的解" src="../n_queens_problem.assets/solution_4_queens.png" /></p>
|
||||
|
Reference in New Issue
Block a user