警示后人之如果你DFSWA#1#6#8#10

B3625 迷宫寻路

xiaozutupian @ 2024-11-11 15:34:24

正确代码:

    if((!ap[a+1][b])&&a+1<=n) tmp=max(tmp,dfs(a+1,b));
    if((!ap[a][b+1])&&b+1<=m) tmp=max(tmp,dfs(a,b+1));
    if((!ap[a-1][b])&&a-1>=1) tmp=max(tmp,dfs(a-1,b));
    if((!ap[a][b-1])&&b-1>=1) tmp=max(tmp,dfs(a,b-1));
        return tmp;

错误代码:

    if((!ap[a+1][b])&&a+1<=n) tmp=tmp or dfs(a+1,b);
    if((!ap[a][b+1])&&b+1<=m) tmp=tmp or dfs(a,b+1);
    if((!ap[a-1][b])&&a-1>=1) tmp=tmp or dfs(a-1,b);
    if((!ap[a][b-1])&&b-1>=1) tmp=tmp or dfs(a,b-1);
    return tmp;

|