#include
using namespace std;
int dx[] = { 2,1,-1,-2,-2,-1,1,2 };
int dy[] = { 1,2,2,1,-1,-2,-2,-1 };
int** crchestboard(int r, int c);
void knight(int x, int y, int **board, int r,int c,int step);
void coutb(int **board, int r, int c);
int main() {
int step = 1;
int r,c,x,y;
cin >> r >> c;
int** chestboard = crchestboard(r,c);
cin >> x >> y;
knight(x, y, chestboard,r,c, step);
}
int **crchestboard(int r, int c) {
int **chestboard = new int* [r];
for (int i = 0; i < r; i++) {
chestboard[i] = new int[c];
}
return chestboard;
}
void knight(int x, int y,int **board, int r,int c,int step) {
if (step>=r*c) {
coutb(board,r,c);
}
else {
//available steps
for (int i = 0; i = 0 && yy >= 0 && xx < r &&yy
Подробнее здесь: [url]https://stackoverflow.com/questions/78254513/how-could-i-solve-the-knights-tour-problem[/url]
Я пытаюсь решить рыцарский тур, и вот мой код. Я не знаю, почему это выглядит слишком странно. Я не знаю, почему рекурсия не работает. [code]#include using namespace std;
int dx[] = { 2,1,-1,-2,-2,-1,1,2 }; int dy[] = { 1,2,2,1,-1,-2,-2,-1 };
int** crchestboard(int r, int c); void knight(int x, int y, int **board, int r,int c,int step); void coutb(int **board, int r, int c);
int main() { int step = 1; int r,c,x,y; cin >> r >> c; int** chestboard = crchestboard(r,c); cin >> x >> y; knight(x, y, chestboard,r,c, step); }
int **crchestboard(int r, int c) { int **chestboard = new int* [r]; for (int i = 0; i < r; i++) { chestboard[i] = new int[c]; } return chestboard; }
void knight(int x, int y,int **board, int r,int c,int step) { if (step>=r*c) { coutb(board,r,c); } else { //available steps for (int i = 0; i = 0 && yy >= 0 && xx < r &&yy