数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 4930|回复: 4

急求八皇后问题matlab程序

[复制链接]
发表于 2005-9-15 09:25:48 | 显示全部楼层 |阅读模式
如题,每次只要搜索到一个皇后即可,要求效率要高,万分感谢!!!
 楼主| 发表于 2005-9-15 19:11:33 | 显示全部楼层
没人会吗?指点一下啊!!!
发表于 2005-9-23 02:04:29 | 显示全部楼层
<>so easy</P>
发表于 2005-9-23 02:08:18 | 显示全部楼层
<>function [a,b]=aa<BR>i=1;<BR>for x1=1:8,<BR>    for x2=1:8,<BR>        if panduan([x1 x2]),<BR>            continue;<BR>        end<BR>        for x3=1:8,<BR>            if panduan([x1 x2 x3]),<BR>                 continue;<BR>             end<BR>            for x4=1:8,<BR>                if panduan([x1 x2 x3 x4]),<BR>                      continue;<BR>                  end                  <BR>                for x5=1:8,<BR>                    if panduan([x1 x2 x3 x4 x5]),<BR>                         continue;<BR>                     end<BR>                    for x6=1:8,<BR>                        if panduan([x1 x2 x3 x4 x5 x6]),                  <BR>                                continue;<BR>                        end<BR>                        for x7=1:8,<BR>                            if panduan([x1 x2 x3 x4 x5 x6 x7]),                  <BR>                                continue;<BR>                            end<BR>                            for x8=1:8,<BR>                                if panduan([x1 x2 x3 x4 x5 x6 x7 x8]),                  <BR>                                    continue;<BR>                                end<BR>                                a(1,x1,i)=1;<BR>                                a(2,x2,i)=1;<BR>                                a(3,x3,i)=1;<BR>                                a(4,x4,i)=1;<BR>                                a(5,x5,i)=1;<BR>                                a(6,x6,i)=1;<BR>                                a(7,x7,i)=1;<BR>                                a(8,x8,i)=1;<BR>                                b(i,=[x1 x2 x3 x4 x5 x6 x7 x8];<BR>                                i=i+1;<BR>                            end<BR>                        end<BR>                    end<BR>                end<BR>            end<BR>        end<BR>    end<BR>end<BR></P>
<>function a=panduan(x)<BR>global ii<BR>l=length(x);<BR>b=x(end);<BR>c=x(1);<BR>ii=ii+1;<BR>if b==c|b==c+l-1|b==c-l+1,<BR>    a=1;<BR>elseif l==2,<BR>    a=0;<BR>else<BR>    a=panduan(x(2:end));<BR>end</P>

<>一共92种</P>
发表于 2005-10-2 09:40:30 | 显示全部楼层
<>这个是递归吗?   刚学建模不会用matlab   C++等语言可以用回溯法</P>
<>解12皇后的问题用时不到2秒(amd 1.5G CPU),总共14200个解</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-6-10 09:45 , Processed in 0.055321 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表