代码如下:
#include <bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,fx,fy,tot;
int ne[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int mapk[105][7];
void dfs(int x,int y)
{
if(x==fx && y==fy)
{
tot++;
return;
}
for(int k=0; k<=3; k++)
{
if(x+ne[k][0]<1 || x+ne[k][0]>n) continue;
if(y+ne[k][1]<1 || y+ne[k][1]>m) continue;
if(mapk[x+ne[k][0]][y+ne[k][1]]==0)
{
x=x+ne[k][0];
y=y+ne[k][1];
mapk[x][y]=1;
dfs(x,y);
mapk[x][y]=0;
}
}
return;
}
int main()
{
cin>>n>>m>>t;
cin>>sx>>sy>>fx>>fy;
mapk[sx][sy]=1;
for(int i=1; i<=t; i++)
{
int x,y;
cin>>x>>y;
mapk[x][y]=2;
}
dfs(sx,sy);
cout<<tot;
return 0;
}
十分感激。