题解
2024-12-08 18:21:18
发布于:广东
6阅读
0回复
0点赞
#include <iostream>
using namespace std;
const int N = 15;
int n, m, sx, sy, fx, fy, t, cnt;
int mp[N][N];
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
bool vis[N][N]; //vis[x][y] 标记点(x,y)是否已访问
bool check(int x, int y){
return x >= 1 && x <= n && y >= 1 && y <= m;
}
void dfs(int x, int y){
if(x == fx && y == fy){
cnt++;
return;
}
vis[x][y] = true;
for(int i = 0; i < 4; i++){
int nx = x + dir[i][0];
int ny = y + dir[i][1];
if(check(nx,ny) && !vis[nx][ny] && mp[nx][ny] != 1){
dfs(nx, ny);
}
}
vis[x][y] = false;
}
int main() {
cin >> n >> m >> t;
cin >> sx >> sy >> fx >> fy;
for(int i = 1; i <= t; i++){
int x, y;
cin >> x >> y;
mp[x][y] = 1;
}
dfs(sx,sy);
cout << cnt;
return 0;
}
这里空空如也
有帮助,赞一个