@[patrickwen](/user/1099787) 你的判断是否到终点的语句应该放到打访问标记的后面,然后dfs最后一行进行回溯。
by tanzicheng @ 2024-03-16 11:21:39
@[tanzicheng](/user/1084317)
感谢
by patrickwen @ 2024-03-16 11:23:32
```cpp
#include <bits/stdc++.h>
using namespace std;
int n,m,sx,sy,vx,vy,tt,fx,fy,tx,ty,ans=0;
int a[105][105]={0};
bool vis[105][105];
void dfs(int x, int y) {
if(x<1||x>n){
return;
}
if(y<1||y>m){
return;
}
if(a[x][y] == 1){
return;
}
if(vis[x][y]==1){
return;
}
if(x ==fx && y ==fy) {
ans++;
return ;
}
vis[x][y]=1;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
vis[x][y]=0;
}
int main(void) {
cin>>n>>m>>tt>>sx>>sy>>fx>>fy;
for(int i=1;i<=tt;i++){
cin>>tx>>ty;
a[tx][ty]=1;
}
dfs(sx,sy);
cout<<ans<<endl;
}
```
by tanzicheng @ 2024-03-16 11:23:58