骑士巡游问题matlab,骑士巡游问题,为什么N的值大于7以后程序就无法运行了

#include

#include

using namespace std;

const int N = 8, STEPS = N*N-1;

int border[N][N];

bool move(int currentRow, int currentColumn, int steps)

{

if (currentRow<0 || currentRow > N - 1 || currentColumn<0 || currentColumn > N - 1)

return false;

if (steps == -1)

return true;

if (border[currentRow][currentColumn] != 0)

return false;

steps--;

border[currentRow][currentColumn] = STEPS - steps;

if (move(currentRow + 1, currentColumn + 2, steps) == true)return true;

if (move(currentRow + 1, currentColumn - 2, steps) == true)return true;

if (move(currentRow - 1, currentColumn + 2, steps) == true)return true;

if (move(currentRow - 1, currentColumn - 2, steps) == true)return true;

if (move(currentRow + 2, currentColumn + 1, steps) == true)return true;

if (move(currentRow + 2, currentColumn - 1, steps) == true)return true;

if (move(currentRow - 2, currentColumn + 1, steps) == true)return true;

if (move(currentRow - 2, currentColumn - 1, steps) == true)return true;

border[currentRow][currentColumn] = 0;

return false;

}

int main()

{

int CurrentRow = 0, CurrentColumn = 0;

for(CurrentRow=0;CurrentRow 

for (CurrentColumn = 0; CurrentColumn 

{

cout <

if (move(CurrentRow, CurrentColumn, STEPS) == true)

{

for (int i = 0; i 

{

for (int j = 0; j 

{

cout.fill('0');

cout.width(2);

cout <

}

cout <

}

}

else

{

cout <

}

}

}

编写程序求解骑士巡游问题:在n行n列的棋盘上(如n=5),假设一位骑士(按象棋中“马走日”的行走法)从初始坐标位置(x1,y1)出发,要遍访(巡游)棋盘中的每一个位置一次。请编一个程序,为骑士求解巡游“路线图”(或告诉骑士,从某位置出发时,无法遍访整个棋盘—问题无解)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值