p1605 迷宫

mac2024-01-25  34

题目大意

#include<iostream> #include<cstring> #include<cstdio> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 15; int n,m,t,cnt=0; int sx,sy,fx,fy; int a[maxn][maxn]; int vis[maxn][maxn]; struct node{ int x,y; }pos[maxn]; void Init(){ pos[0].x=-1;pos[0].y=0; pos[1].x=1;pos[1].y=0; pos[2].x=0;pos[2].y=-1; pos[3].x=0;pos[3].y=1; memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); } void dfs(int x,int y) { //cout<<x<<" "<<y<<endl; if(x==fx&&y==fy){ cnt++; return ; } for(int i=0;i<4;i++){ int r=x+pos[i].x,l=y+pos[i].y; //cout<<x<<" "<<y<<" "<<r<<" "<<l<<endl; if(r<=n&&r>=1&&l<=m&&l>=1){ if(a[r][l]!=1&&vis[r][l]==0){ vis[r][l]=1; dfs(r,l); vis[r][l]=0; } } } } int main() { cin>>n>>m>>t; cin>>sx>>sy>>fx>>fy; Init(); while(t--){ int x,y; scanf("%d%d",&x,&y); a[x][y]=1; } vis[sx][sy]=1; dfs(sx,sy); cout<<cnt<<endl; }
最新回复(0)