#include<bits/stdc++.h>
using namespace std;
int n,a[11][11];
int vis[11][11];
int dx[5]={0,0,-1,1};
int dy[5]={-1,1,0,0};
int maxn=-1;
int sum=0,cnt=0;
int s1,s2;
void dfs(int x,int y){
if(cnt>s1||cnt>s2)
return;
if(x==n&&y==n){
maxn=max(maxn,sum);
return;
}
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(xx>=1&&xx<=n&&yy>=1&&yy<=n&&vis[xx][yy]==0&&a[xx][yy]!=-1){
vis[xx][yy]=1;
sum+=a[xx][yy];
cnt=a[xx][yy];
dfs(xx,yy);
vis[xx][yy]=0;
sum-=a[xx][yy];
cnt=0;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char ch;
cin>>ch;
if(ch<='9'&&ch>='0')
a[i][j]=ch-'0';
else if(ch=='.')
a[i][j]=0;
else
a[i][j]=-1;
}
}
cin>>s1>>s2;
dfs(1,1);
if(maxn==-1)
cout<<"Oh,dead...Well,that's great.";
else
cout<<maxn;
return 0;
}
共 1 条回复
题目要求有两个输出,你的只有一个