下载此文档

八皇后递归算法Eightqueensrecursivealgorithm.doc


文档分类:IT计算机 | 页数:约10页 举报非法文档有奖
1/10
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/10 下载此文档
文档列表 文档介绍
八皇后递归算法(Eight queens recursive algorithm)
First, the purpose and content of the experiment
Write a program to solve thessful, return true by referring to the parameter OK (otherwise returning false).
Void solve (int, I, bool&, OK);
After the queen is placed, if the i=8 is full then the recursive exit: otherwise, solve (i+1, OK); recursive call.
the preparation of the main function, first initialize a /zempty chessboard”, each element is a, B, C array are set to true (the queen said has not been placed in 8 rows, the current board of the 15 diagonal and 15 anti diagonal.). Then, execute the calling statement solve (1, OK) ; it is responsible for placing the queen on the 8 consecutive column starting at the first column; if successful, return true by referring to the parameter OK (otherwise returning false).
appendix
Source code 1 (output all 92 sets of solutions)
ftinclude "iostream, h""
Int LineNum [9];
Bool, a[9], b[15], c[15]:
Int totalmethod-0:
Void, print ();
Void solve (int, N, bool & OK);
Int main (int, argc, char*, argv[])
{
Bool ok=false:
For (int i=l: i<=8: i++)
A[i]=true;
For (int j=0; j<=14; j++)
(b[j]=true; c[j]=true;}
Solve (1, OK);
}
Void, print ()
{
Int, I, j:
Totalmethod++;
Cout<< "method:" <<totalmethod<<endl;
For (i=l: i<=8: i++)
{cout<< ”(" <〈i〈< " <<LineNum[i]<< ,z);}
Cout«endl;
For (i=l: i<=8; i++)
{
For (j=l: j<=8; j++)
{

八皇后递归算法Eightqueensrecursivealgorithm 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数10
  • 收藏数0 收藏
  • 顶次数0
  • 上传人蓝天
  • 文件大小84 KB
  • 时间2022-06-17
最近更新