https://www.luogu.org/problemnew/show/P1006

类似于https://www.luogu.org/problemnew/show/P1002

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG

using namespace std;
typedef long long ll;
const int N=55;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m;
int a[N][N];
int dp[N][N][N][N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            for(int k=1;k<=n;k++){
                int l=i+j-k;
                if(l<=0)
                    break;
                if(l>m)
                    continue;
                dp[i][j][k][l]=max(dp[i-1][j][k-1][l],max(dp[i-1][j][k][l-1],max(dp[i][j-1][k][l-1],dp[i][j-1][k-1][l])));
                if(i==k&&j==l)
                    dp[i][j][k][l]+=a[i][j];
                else
                    dp[i][j][k][l]+=a[i][j]+a[k][l];
            }
    cout << dp[n][m][n][m] << endl;
    //cout << "Hello world!" << endl;
    return 0;
}