50分求助!!!!!
  • 板块P1605 迷宫
  • 楼主GEZHENHAO
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/7/10 16:09
  • 上次更新2024/7/10 17:03:12
查看原帖
50分求助!!!!!
1230616
GEZHENHAO楼主2024/7/10 16:09
#include<bits/stdc++.h>
using namespace std;
int a[11][11],used[11][11],dx[5]{0,1,-1,0,0},dy[5]{0,0,0,1,-1};
bool vis[6][6];
int n,m,t,sx,sy,fx,fy,tx,ty,ans=0;
void dfs(int x,int y)
{
    if(x==fx&&y==fy)
    {
    	ans++;
    	return;
	}
  for (int i=1;i<4;i++)
  {
  	int nx=x+dx[i];
  	int ny=y+dy[i];
  	if ((nx>=1&&nx<=n)&&(ny>=1&&ny<=m)&&(!vis[nx][ny]))
  	{
  		vis[nx][ny]=1;
	 	dfs(nx,ny);
	 	vis[nx][ny]=0;
	 }
  }
}  
int main()  
{   
    cin>>n>>m>>t>>sx>>sy>>fx>>fy;
    for (int i=1;i<=t;i++)
    {
    	cin>>tx>>ty;
		vis[tx][ty]=1;
	}
	vis[sx][sy]=1;
	dfs(sx,sy);
	cout<<ans; 
    return 0;  
}  
2024/7/10 16:09
加载中...