我使用的方法是:
下面是我的代码:
#include <bits/stdc++.h>
using namespace std;
int chess[30][30], n, m, hx, hy, dir[9][2] = {
{-2, -1},
{-1, -2},
{2, -1},
{-1, 2},
{-2, 1},
{1, -2},
{2, 1},
{1, 2},
{0, 0}
};
struct Pos {
int x, y;
};
int main() {
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
chess[i][j] = -1;
}
}
cin >> n >> m >> hx >> hy;
for (int i = 0; i <= n; i++) {
chess[i][0] = 1;
}
for (int i = 1; i <= m; i++) {
chess[0][i] = 1;
}
for (int i = 0; i < 9; i++) {
chess[hx + dir[i][0]][hy + dir[i][1]] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (chess[i][j] == -1) {
chess[i][j] = chess[i - 1][j] + chess[i][j - 1];
}
}
}
cout << chess[n][m] << endl;
return 0;
}
我用来调试这段代码的代码如下:
void print() {
system("cls");
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
printf("%3d", chess[i][j]);
}
cout << endl;
}
return;
}
,未能从结果中得到帮助。