dfs中需要加越界特判
```cpp
#include<bits/stdc++.h>
using namespace std;
int sum = 0;
int a[10][10];
int dx[5] = {0,-1,0,1,0};
int dy[5] = {0,0,1,0,-1};
int n,m,t;
int sx,sy,ex,ey;
void dfs(int x,int y)
{
if(x == ex && y == ey)
{
sum++;
return ;
}
for(int i = 1;i <= 4;i++){
int tx = x + dx[i];
int ty = y + dy[i];
if(a[tx][ty] == 0 &&tx <= n && tx >= 1 && ty >= 1 && ty <= m)
{
a[tx][ty] = 1;
dfs(tx,ty);
a[tx][ty] = 0;
}
}
}
int main()
{
cin >> n >> m >> t;
cin >> sx >> sy >> ex >> ey;
for(int i = 1;i <= t;i++)
{
int x,y;
cin >> x >> y;
a[x][y] = 1;
}
a[sx][sy] = 1;
dfs(sx,sy);
cout << sum << endl;
return 0;
}
```
by jasonxue2012 @ 2022-11-19 20:03:26