1 #include<cstdio>
2 #include<iostream>
3 using namespace std;
4
5 int dp[55][55][55][55];
6 int n, m;
7 int map[55][55];
8
9 int main()
10 {
11 scanf("%d%d", &n, &m);
12 for(int i = 1; i <= n; i++)
13 for(int j = 1; j <= m; j++)
14 scanf("%d", &map[i][j]);
15 for(int i = 1; i <= n; i++)
16 {
17 for(int j = 1; j <= m; j++)
18 {
19 for(int k = 1; k <= n; k++)
20 {
21 int l;
22 if(i + j - k > 0)l = i + j - k;
23 else continue;
24 dp[i][j][k][l]=max(max(dp[i-1][j][k-1][l],dp[i-1][j][k][l-1]),max(dp[i][j-1][k-1][l],dp[i][j-1][k][l-1]))+map[i][j]+map[k][l];
25 if(i == k && j == l)dp[i][j][k][l] -= map[i][j];
26 }
27 }
28 }
29 printf("%d\n",dp[n][m][n][m]);
30 return 0;
31 }