擅长:python、mysql、java
<p>我建议您查看Python源代码中的<a href="http://svn.python.org/view/python/trunk/Lib/test/test_generators.py?revision=77983&view=markup" rel="nofollow">^{<cd1>}</a>,以获得N皇后问题的另一个实现。</p>
<pre><code>Python 2.6.5 (release26-maint, Sep 12 2010, 21:32:47)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from test import test_generators as tg
>>> n= tg.Queens(15)
>>> s= n.solve()
>>> next(s)
[0, 2, 4, 1, 9, 11, 13, 3, 12, 8, 5, 14, 6, 10, 7]
>>> next(s)
[0, 2, 4, 6, 8, 13, 11, 1, 14, 7, 5, 3, 9, 12, 10]
</code></pre>