90分求救
  • 板块P1605 迷宫
  • 楼主YunSX
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/11/27 22:18
  • 上次更新2023/11/5 07:13:12
查看原帖
90分求救
431794
YunSX楼主2020/11/27 22:18
#include <iostream>
using namespace std;
int mymap[6][6];
bool vis[6][6];
int _x[4]={0,0,1,-1};
int _y[4]={1,-1,0,0};
int ans=0,fx,fy,x,y,t,n,m;
void dfs(int x,int y){
	if(x==fx&&y==fy){
		ans++;
        return ;
	}
    else{
    	for(int i=0;i<4;i++){
    		int tx=x+_x[i];
    		int ty=y+_y[i];
    		if(mymap[tx][ty]==0&&tx>0&&tx<=n&&ty>0&&ty<=m&&!vis[tx][ty]){
    			vis[tx][ty]=1;
    			dfs(tx,ty);
    			vis[tx][ty]=0;
    		}
    	}
    }
} 
int main() {
	cin>>n>>m>>t;
	cin>>x>>y>>fx>>fy;
	for(int i=0;i<t;i++){
		int ax=0,ay=0;
		cin>>ax>>ay;
		mymap[ax][ay]=1;
	}
    vis[1][1]=1;
	dfs(x,y);
	cout<<ans<<endl;
	return 0;
}
2020/11/27 22:18
加载中...