Wie könnte ich das Tourproblem des Ritters lösen?C++

Programme in C++. Entwicklerforum
Anonymous
 Wie könnte ich das Tourproblem des Ritters lösen?

Post by Anonymous »

Ich versuche die Rittertour zu lösen und hier ist mein Code. Ich weiß nicht, warum es zu seltsam läuft. Ich weiß nicht, warum die Rekursion nicht funktioniert.

Code: Select all

#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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post