马跑日算法

来源:互联网 发布:mac 的idea提示快捷键 编辑:程序博客网 时间:2024/06/05 15:48

马跑日算法

算法:

#include <stdio.h>using namespace std;//开始计算;bool  Search(  Location  curLoc  ){       m_complex  ;       //修改棋盘标志;       m_chessTable[ curLoc.x-1 ][ curLoc.y-1 ] = 1;       //是否搜索成功结束标志;       if( isSuccess() )              return true;       //还有未走到的棋盘点,从当前位置开始搜索;       else       {              //递归搜索未走过的棋盘点;              for( int i = 0 ; i < 8 ; i   )              {                     Location newLocation = GetSubTreeNode( curLoc , i ) ;                     if(  isValide( newLocation ) &&            m_chessTable[newLocation.x-1][newLocation.y-1] == 0  )                     {                            if( Search( newLocation ) == true )                            {                                   //填写记录表;                                   MarkInTable( newLocation, curLoc );                                   return true;                            }                     }              }       }       //搜索失败,恢复棋盘标志;       m_chessTable[curLoc.x-1][curLoc.y-1] = 0;       return false;}
0 0