求助,蒟蒻不知道错哪了

P1649 [USACO07OCT] Obstacle Course S

风中の菜鸡 @ 2021-06-19 17:57:24

#include<bits/stdc++.h>
using namespace std;
char a[110][110];
int n,aaa,b,aa,bb;
int t,l;
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int bj=1;
int use[110][110];
int minn=1e9;
void dfs(int x,int  y,int ans=0){
    if(x==aa&&y==bb){
        if(ans<minn){
            minn=ans;
            return;
        }
    }
    for(int i=0;i<4;i++){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(use[xx][yy]==0&&xx>=1&&yy>=1&&xx<=n&&yy<=n&&a[xx][yy]!='x'){
            use[xx][yy]=1;
            if(t==dx[i]&&l==dy[i])
            dfs(xx,yy,ans);
            else if(t!=dx[i]||l!=dy[i]){
                t=dx[i],l=dy[i];
                dfs(xx,yy,ans+1);
            }
        }
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            if(a[i][j]=='A')
            aaa=i,b=j;
            if(a[i][j]=='B')
            aa=i,bb=j;
        }
    }
    dfs(aaa,b,0);
    minn--;
    cout<<minn;
return 0;
}

样例过了,但全挂


by Aukari @ 2021-06-19 18:07:31

您有加-1的判断吗


by 风中の菜鸡 @ 2021-06-19 18:08:47

@⚡EthanCai⚡ 这是一个错误,谢谢您


|