c++ - Knight 的巡回递归只填满了 60 个方格
问题描述
我几天来一直在研究这个骑士的巡回递归问题,但仍然找不到解决方案。有人可以帮我找出错误吗?我一直在寻找它,它可以填充的最大瓷砖只有60。我不知道错误是什么。这是我的代码:
#include <iostream>;
#include <string>;
#include <vector>;
#include <cstdlib>;
#include <cmath>;
#include <ctype.h>;
#include <ctime>;
#include <stdlib.h>;
using namespace std;
int step=1, v[8][8], x[8], y[8];
bool success;
bool SolveKnightTour(int step, int xc, int yc){
if (step>64){
success=true;
}
else {
success=false;
int move=0;
while(move<8 & success==false){
if (xc+x[move]>=0 & xc+x[move]<8 & yc+y[move]>=0 & yc+y[move]<8 & v[yc+y[move]][xc+x[move]]==0){
v[yc+y[move]][xc+x[move]]=step+1;
if (!SolveKnightTour(step+1, xc+x[move], yc+y[move])){
v[yc+y[move]][xc+x[move]]=0;
}
}
if (success==false){
move++;
}
}
}
return success;
}
int main(){
int i, j;
x[0]=1, y[0]=-2;
x[1]=2, y[1]=-1;
x[2]=2, y[2]=1;
x[3]=1, y[3]=2;
x[4]=-1, y[4]=2;
x[5]=-2, y[5]=1;
x[6]=-2, y[6]=-1;
x[7]=-1, y[7]=-2;
for (i=0;i<8;i++){
for (j=0;j<8;j++){
v[i][j]=0;
}
}
v[4][4]=1;
SolveKnightTour(step, 4, 4);
for (i=0;i<8;i++){
for (j=0;j<8;j++){
cout<<v[i][j]<<" ";
}
cout<<"\n";
}
system("pause");
return 0;
}
任何帮助是极大的赞赏。
解决方案
推荐阅读
- node.js - 如何从nodejs中的CSVTOJSON中仅提取某些字段?
- mysql - 如何将此复杂查询转换为等效的 Django ORM
- sql - 从动态链接服务器存储过程返回值
- r - .Rproj 文件无法使用 Rstudio 启动
- google-apps-script - 如何使用 Google Apps 脚本在父文件夹及其子文件夹中搜索并获取特定文件?
- c - 在双向链表中实现删除位置功能的问题
- java - 排序列表
每个基于第一个元素 - css - 在 Flex Tailwind 上设置固定间隙
- google-cloud-platform - Terraform 状态锁无法在 GCP 后端释放
- c++ - Microsoft Compiler 中的宏导致的编译错误