我尝试使用“标数法”和C++来解决这道题,但是没有成功
查看原帖
我尝试使用“标数法”和C++来解决这道题,但是没有成功
378418
Chenaknoip楼主2021/10/10 17:56

我使用的方法是:

  1. 将最左边和最上边全部赋值为 11;
  2. 将马的控制点和马的位置赋值为 00;
  3. 把一个点的正上方和左边的数加起来,就是这个点的可能次数。

下面是我的代码:

#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;
} 

,未能从结果中得到帮助。

2021/10/10 17:56
加载中...