70求助
查看原帖
70求助
351081
万灭、蓝鲸楼主2021/1/1 18:30
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;

int dx[5] = {0, -1, 0, 1, 0};
int dy[5] = {0, 0, 1, 0, -1};
int n, m, t, sx, sy, ex, ey, ans, a[15][15];

int read()
{
	int sum = 0, w = 1;
    char ch = getchar();
    while (ch != '-' && !isdigit(ch))  ch = getchar();
    if (ch == '-')  w = -1, ch = getchar();
    while(isdigit(ch))  sum = (sum << 3) + (sum << 1) + ch - '0', ch = getchar();
    return sum * w;
}

void dfs(int x, int y)
{
	if (x == ex && y == ey)  ans++;
	else
		for (int i = 1; i <= 4; i++)
		{
			int tx = x + dx[i];
			int ty = y + dy[i];
			if (a[tx][ty] == 0)
			{
				a[tx][ty] = -1;
				dfs(tx, ty);
				a[tx][ty] = 0;
			}
		}
}

int main()
{
	memset(a, -1, sizeof(a));
	n = read(), m = read(), t = read();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			a[i][j] = 0;
	sx = read(), sy = read(), ex = read(), ey = read();
	for (int i = 1; i <= t; i++)
		a[read()][read()] = -1;
	dfs(sx, sy);
	cout << ans << endl;
	return 0;
}

应该没有大问题,但是只有70

2021/1/1 18:30
加载中...