很经典的一道DFS题
#include "bits/stdc++.h"
using namespace std;
int a[6][6],ans;
int n,m,t;
bool vis[6][6];//判断是否经历过
int sx,sy,fx,fy;
int mx[4]={0,0,-1,1};
int my[4]={-1,1,0,0};方向数组
void out(int x,int y){
if (x==fx&&y==fy){
ans++;
return;
}
vis[x][y]= true;//标记
for(int i=0;i<=3;i++){
if (a[x+mx[i]][y+my[i]]==0&&vis[x+mx[i]][y+my[i]]==0){
int x1,y1;
x1=x+mx[i];
y1=y+my[i];
if (x1>=1&&x1<=n&&y1>=1&&y1<=m){
out(x1,y1);
vis[x1][y1]= 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;
a[x][y]=1;
}
out(sx,sy);
cout<<ans;
return 0;
}
4085





