#1~#4WA,#5AC,#6~#20TLE
#include<bits/stdc++.h>
using namespace std;
int a[1001][1001],n,m;
bool b[1001][1001];
long long ans=-1145141919810,zhi;
void dfs(int x,int y)
{
if(x==n&&y==m)
{
ans=max(zhi,ans);
return;
}
if(x+1<=n&&!b[x+1][y])
{
b[x+1][y]=true;
zhi+=a[x+1][y];
dfs(x+1,y);
b[x+1][y]=false;
zhi-=a[x+1][y];
}
if(y+1<=m&&!b[x][y+1])
{
b[x][y+1]=true;
zhi+=a[x][y+1];
dfs(x,y+1);
zhi-=a[x][y+1];
b[x][y+1]=false;
}
if(y-1>1&&!b[x][y-1])
{
b[x][y-1]=true;
zhi+=a[x][y-1];
dfs(x,y-1);
b[x][y-1]=false;
zhi+=a[x][y-1];
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
zhi=a[1][1];
dfs(1,1);
cout<<ans;
return 0;
}
只用骗到25分就行了,谢谢各位dalao帮助!