对不起,代码发错了。
上面这段代码中 $14$ ~ $16$ 行没有实际用处。
by jiuyichen @ 2021-10-10 17:59:04
试试样例4 8 2 4,你应该就知道错在哪了,答案是0
by rsrsr @ 2021-10-10 18:15:18
并不是所有最上边和最左边卒都可以到达
by rsrsr @ 2021-10-10 18:18:57
在参考了 rsrsr 大佬的意见后,仍然没有成功。
下面是我的代码:
```cpp
#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}
};
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;
}
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 < 9; i++) {
if (hx + dir[i][0] < 0 || hy + dir[i][1] < 0) {
;
} else {
chess[hx + dir[i][0]][hy + dir[i][1]] = 0;
}
}
int tmp = 1;
for (int i = 0; i <= n; i++) {
if (chess[i][0] != -1) tmp = 0;
chess[i][0] = tmp;
}
for (int i = 1; i <= m; i++) {
if (chess[0][i] != -1) tmp = 0;
chess[0][i] = tmp;
}
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;
}
```
主要改变了这些内容:
1. 当在给表格写入 $1$ 时,遇到 $0$ 就停止。
我最近一次提交 WA 了
by jiuyichen @ 2021-10-13 19:34:04