求助大佬们,第一个点过不去……(哭)
查看原帖
求助大佬们,第一个点过不去……(哭)
113488
张泽洋楼主2023/9/10 17:31
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

long long f[45][45];
int n, m, hx, hy;
bool horse[45][45];

void check_horse(int x, int y)
{
	horse[x][y] = true;
	if (x - 2 >= 0 && y - 1 >= 0) horse[x - 2][y - 1] = true;
	if (x - 2 >= 0 && y + 1 < m) horse[x - 2][y + 1] = true;
	if (x - 1 >= 0 && y - 2 >= 0) horse[x - 1][y - 2] = true;
	if (x - 1 >= 0 && y + 2 < m) horse[x - 1][y + 2] = true;
	if (x + 1 < n && y - 2 >= 0) horse[x + 1][y - 2] = true;
	if (x + 1 < n && y + 2 < m) horse[x + 1][y + 2] = true;
	if (x + 2 < n && y - 1 >= 0) horse[x + 2][y - 1] = true;
	if (x + 2 < n && y + 1 < m) horse[x + 2][y + 1] = true;
}

int main()
{
	cin >> n >> m >> hx >> hy;

	//初始化
	f[0][0] = 1;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
		{
			horse[i][j] = false;
		}
	check_horse(hx, hy);//判断马挡住的点

	for (int i = 0; i <= n; i++)//递推计算
	{
		for (int j = 0; j <= m; j++)
		{
			if (i != 0)
			{
				f[i][j] += f[i - 1][j];
			}
			if (j != 0)
			{
				f[i][j] += f[i][j - 1];
			}
			if (horse[i][j] == true)
			{
				f[i][j] = 0;
			}
		}
	}

	cout << f[n][m] << endl;

	//debug
	/*
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			cout << f[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			cout << horse[i][j] << " ";
		}
		cout << endl;
	}
	*/
	return 0;
}
2023/9/10 17:31
加载中...