8皇后问题(c ++) [英] 8 queens problem(c++)

查看:101
本文介绍了8皇后问题(c ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个带有递归功能的8皇后问题的解决方案。

你请求帮助我吗?

谢谢。

解决方案

如果你要发布你的作业,至少试着让你看起来像是试图自己做一些事情!



我们不这样做做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,或学习魔术词: 你想要炸薯条吗?


阅读带遗传的8皇后区解决方案算法 [ ^ ]

如果我是你,我自己试图解决它,因为它可以帮助你提高编程技巧。



这是一个示例伪代码实现它:



 solve(int rowNo,int totalRows)
{
if(rowNo> totalRows)
转储董事会配置

当前行中的所有单元格
如果可以在此单元格中放置一个女王
{
放置一个女王在这个单元格
所以lve(rowNo + 1,totalRows)
}

}





然后用它调用它价值

解决(1,8); 





你可以转储每次你到达状态树中的叶状态时,你都可以增加一个全局计数器。



希望它有所帮助。


I want a solution for 8 queen problem with recursive function.
whould you pleaze help me?
thanks.

解决方案

If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, or learn the Magic Words: "Do you want fries with that?"


Read 8 Queens Solution with Genetic Algorithm[^]


If I were you I tried to solve it myself because it helps you improve your programming skills.

Here is a sample pseudo code for implementing it :

solve(int rowNo, int totalRows)
{
  if (rowNo>totalRows)
     dump the board configuration

  for all the cells in current row 
    if it is possible to place a queen in this cell
       {
          place a queen in this cell
          solve(rowNo+1, totalRows)
       }

}



Then call it with this values

solve(1, 8);



you can dump the board every time you reach to a leaf state in states tree, or you can increase a global counter.

Hope it helps.


这篇关于8皇后问题(c ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆