想法:
1.典型的dfs
2.注意在开始的时候将st[sx][sy]设为true,起始坐标,深搜时不要再搜回来。否则70分。
AC代码
//要注意开始的时候起始坐标的状态设为true
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int n,m,t,ans;
int sx,sy,fx,fy;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int mp[10][10]={0};
bool st[10][10];
void dfs(int u,int p){
if(u==fx && p==fy){
ans++;
return;
}
else{
for(int i=0;i<4;i++){
int nx=u+dx[i];
int ny=p+dy[i];
if(nx>=1 && nx<=n && ny>=1 && ny <=m && mp[nx][ny]==0 && st[nx][ny]==false){
st[nx][ny] = true;
dfs(nx,ny);
st[nx][ny] = false;
}
}
return;
}
}
int main(){
cin>>n>>m>>t;
cin>>sx>>sy>>fx>>fy;
//!!!!!!
st[sx][sy] = true;
while(t--){
int tx,ty;
cin>>tx>>ty;
mp[tx][ty] = 1;
}
if(n==1 && m==1){
cout<<0<<endl;
return 0;
}
dfs(sx,sy);
cout<<ans<<endl;
return 0;
}