dfs解决问题,
ac代码如下
#include <iostream>
#include <memory.h>
#define N 6
using namespace std;
int n,m,t;
int sx,sy,fx,fy;
int x,y;
int a[N][N];
int vis[N][N];
int f[4][2]={{-1,0},{1,0},{0,-1},{0,1}};//方向数组
int count=0;
void dfs(int a1,int b1){
if(a1==fx&&b1==fy){
count++;
}
if(vis[a1][b1]==1)return;
if(a1<1||a1>n||b1<1||b1>m)return;
for(int i=0;i<4;i++){
int x1=a1+f[i][0];
int y1=b1+f[i][1];
if(vis[x1][y1]==1)continue;
vis[a1][b1]=1;
if(a[x1][y1]==2){
vis[a1][b1]=0;
continue;
}else{
dfs(x1,y1);
vis[a1][b1]=0;
}
}
}
int main()
{
memset(a,0,sizeof(a));
memset(vis,0,sizeof(vis));
cin>>n>>m>>t;
cin>>sx>>sy>>fx>>fy;
while(t--){
cin>>x>>y;
a[x][y]=2;
}
dfs(sx,sy);
cout<<count;
return 0;
}