更尴尬的是结尾cnt / 2,得了30分,实在检查了很久,思路也是对的,希望能指出错误,谢谢
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#define IOS ios::syns_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;
const int maxn = 1e4 + 5;
int n, m, t;
int p[maxn][maxn];
bool vis[maxn][maxn];
int cnt = 0;
void dfs(int x, int y) {
vis[x][y] = true;
if (p[x][y] == 3) {
++cnt;
return ;
}
for (int i = -1; i <= 1; ++i) {
for (int j = -1; j <= 1; ++j) {
if (x + i > 0 && y + j > 0 && x + i <= n && y + j <= m && p[x + i][y + j] != 2 && vis[x + i][y + j] == false) {
dfs(x + i, y + j);
vis[x + i][y + j] = false;
}
}
}
}
int main() {
int x1, y1;
int x, y;
scanf("%d %d %d", &n, &m, &t);
scanf("%d %d", &x1, &y1);
scanf("%d %d", &x, &y);
p[x][y] = 3;//终点
for (int i = 0; i < t; ++i) {
scanf("%d %d", &x, &y);
p[x][y] = 2;
}
dfs(x1, y1);
printf("%d", cnt);
return 0;
}