迷宫之方案数
2025-01-22 14:06:06
发布于:上海
#include<bits/stdc++.h>
using namespace std;
int n,m,t;
int sx,sy,fx,fy;
int ans;
int to[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int a[10][10];
bool vis[20][20];
bool check(int x,int y){
return x>0&&x<=n&&y>0&&y<=m;
}
void dfs(int x,int y){
if(x == fx&&y == fy){
ans++;
}
for(int i = 0;i<4;i++){
int nx = x + to[i][0];
int ny = y + to[i][1];
if(check(nx,ny)&&a[nx][ny]!=1&&!vis[nx][ny]){
vis[nx][ny] = true;
dfs(nx,ny);
vis[nx][ny] = false;
}
}
}
int main(){
cin>>n>>m>>t;
cin>>sx>>sy>>fx>>fy;
for(int i = 1;i<=t;i++){
int x,y;
cin>>x>>y;
a[x][y] = 1;
}
vis[sx][sy] = true;
dfs(sx,sy);
cout<<ans;
return 0;
}
这里空空如也
有帮助,赞一个