Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 51
using namespace std;
int dp[N][N][N][N],a[N][N],n,m;
void solve(int i,int j,int k,int l){
int Max = 0;
Max = max(Max,dp[i-1][j][k-1][l]);
Max = max(Max,dp[i-1][j][k][l-1]);
Max = max(Max,dp[i][j-1][k][l-1]);
Max = max(Max,dp[i][j-1][k-1][l]);
dp[i][j][k][l] = Max + a[i][j];
if(i != k || j != l) dp[i][j][k][l] += a[k][l];
}
int main(){
scanf("%d%d",&m,&n);
for(int i = 1;i <= m;++i){
for(int j = 1;j <= n;++j){
scanf("%d",&a[i][j]);
}
}
for(int i = 1;i <= m;++i)
for(int j = 1;j <= n;++j)
for(int k = 1;k <= m;++k)
for(int l = 1;l <= n;++l)
solve(i,j,k,l);
printf("%d
",dp[m][n][m][n]);
return 0;
}