https://www.luogu.org/problemnew/show/P1006
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[105][55][55];
int mp[55][55];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&mp[i][j]);
for(int p=2;p<=m+n-1;p++)
for(int i=1;i<=p&&i<=n;i++)
for(int j=1;j<=i&&j<=p;j++)
{
f[p][i][j]=max(max(f[p-1][i][j],f[p-1][i-1][j]),max(f[p-1][i][j-1],f[p-1][i-1][j-1]));
if(i==j) f[p][i][j]+=mp[i][p-i+1];
else f[p][i][j]+=mp[i][p-i+1]+mp[j][p-j+1];
}
printf("%d",f[n+m-1][n][n]);
}