RT,爆搜做的,没T,但全WA qaq
#include<iostream>
using namespace std;
typedef long long ll;
ll G[1001][1001],vis[1001][1001];
ll n,m;
ll ans=-2147483648;
ll dx[]={-1,1,0},dy[]={0,0,1};
bool inside(ll x,ll y){
if(x>=1 and x<=n and y>=1 and y<=m)return true;
else return false;
}
void dfs(ll x,ll y,ll sum){
if(x==n and y==m){
ans=max(sum+G[x][y],ans);
return;
}
sum+=G[x][y];
for(ll i=0;i<3;i++){
ll nx=x+dx[i],ny=y+dy[i];
if(inside(nx,ny) and not vis[nx][ny]){
vis[nx][ny]=1;
dfs(nx,ny,sum);
}
}
}
int main(){
cin>>n>>m;
vis[1][1]=1;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++)cin>>G[i][j];
}
dfs(1,1,G[1][1]);
cout<<ans;
return 0;
}