70分求助!!!

P1605 迷宫

@[biophitma_wby](/user/640477) ``` #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cstdio> using namespace std; int n,m,t; int sx,sy,fx,fy; bool s[10][10]; int sum=0; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; void dfs(int x,int y){ if(x==fx&&y==fy){ sum++; return; }else{ for(int i=0;i<4;i++){ int nx=x+dx[i],ny=y+dy[i]; if(s[nx][ny]==false&&nx>=1&&nx<=n&&ny>=1&&ny<=m){ s[nx][ny]=true; dfs(nx,ny); s[nx][ny]=false; } } } } int main(){ cin>>n>>m>>t; cin>>sx>>sy>>fx>>fy; for(int i=1;i<=t;i++){ int a,b; cin>>a>>b; s[a][b]=true; } s[sx][sy]=1;//起点也要标记走过 dfs(sx,sy); cout<<sum; return 0; } ```
by QWQ_123456fyy @ 2022-08-04 20:05:10


@[123456fyy](/user/690507) 太感谢了
by biophitma_wby @ 2022-08-04 20:27:47


|