#include <bits/stdc++.h>\nusing namespace std;
typedef long long ll;
ll n,m,X[109][109],j,s,q,p,tot;
\nvoid dfs(ll x,ll y){
\tX[x][y]=0;
\tif(x==j&&y==s){
\t tot++;
\t return;
\t}
\tif(X[x+1][y]){
\t dfs(x+1,y);
\t X[x+1][y]=1;
\t}\t\t
\tif(X[x][y+1]){
\t dfs(x,y+1);
\t X[x][y+1]=1;
\t}\t\t
\tif(X[x-1][y]){
\t dfs(x-1,y);
\t X[x-1][y]=1;
\t}\t\t
\tif(X[x][y-1]){
\t dfs(x,y-1);
\t X[x][y-1]=1;
\t}
}
\nint main() {
\tcin>>n>>m;
\tfor(int i=1;i<=n;i++){
\t for(int j=1;j<=m;j++){
\t cin>>X[i][j];\ \t
\t }
\t}
\tcin>>q>>p>>j>>s;
\tdfs(q,p);
\tcout<<tot;
\treturn 0;
}

C++ 递归算法优化 - 避免不必要的循环和错误退出

原文地址: https://www.cveoy.top/t/topic/pUoo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录