求助玄一关
查看原帖
求助玄一关
1117573
ylswznzs楼主2024/4/2 18:02

WA on #1#3#10#13#19#20#27#28#29#32#33#34 求助

#include <iostream>
using namespace std;
int a[10100][10010];//图
int maxn=0,ans=0,R,C,A,B;//最多能获得的钱数、一次获得的钱数
void dfs(int x,int y)//现在在(x,y)位置上
{
    ans+=a[x][y];//加上这个位置的钱数
    a[x][y]=-1;//不能再走了,标成干草
    if (x>=0&&x<=R-1&&y+1>=0&&y+1<=C-1&&a[x][y+1]!=-1)dfs(x,y+1);//如果可以向右
    else if (x+1>=0&&x+1<=R-1&&y>=0&&y<=C-1&&a[x+1][y]!=-1)dfs(x+1,y);//向下
    else if (x-1>=0&&x-1<=R-1&&y>=0&&y<=C-1&&a[x-1][y]!=-1)dfs(x-1,y);//向上
    else if (x>=0&&x<=R-1&&y-1>=0&&y-1<=C-1&&a[x][y-1]!=-1)dfs(x,y-1);//向左
    else //如果都走不通,结束
    {
        maxn=max(maxn,ans);//更新答案
        ans=0;//ans为0
        return;
    }
    //return;
}
int main()
{
    cin>>R>>C;
    for (int i=0;i<R;i++)
    {
        for (int j=0;j<C;j++)
        {
            char s;
            cin>>s;
            if (s=='L')a[i][j]=10;
            if (s=='M')a[i][j]=5;
            if (s=='S')a[i][j]=1;
            if (s=='*')a[i][j]=-1;
          	  //按照种类标记位置的钱数
        }
    }
    cin>>A>>B;
    dfs(A,B);
    cout<<maxn;
    return 0;
}
2024/4/2 18:02
加载中...