1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 typedef long long ll; 4 using namespace std; 5 inline ll read() 6 { 7 ll ans = 0; 8 char ch = getchar(), last = ' '; 9 while(!isdigit(ch)) last = ch, ch = getchar(); 10 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 11 if(last == '-') ans = -ans; 12 return ans; 13 } 14 inline void write(ll x) 15 { 16 if(x < 0) x = -x, putchar('-'); 17 if(x >= 10) write(x / 10); 18 putchar(x % 10 + '0'); 19 } 20 int n,m; 21 int a[52][52]; 22 int dp[52][52][52][52]; 23 int MightyMaXXX(int a,int b,int c,int d) 24 { 25 if(a<b) a=b; 26 if(a<c) a=c; 27 if(a<d) a=d; 28 return a; 29 } 30 int main() 31 { 32 cin >> n >> m; 33 _for(i,1,n+1) 34 _for(j,1,m+1) 35 cin >> a[i][j]; 36 37 _for(i,1,n+1) 38 _for(j,1,m+1) 39 _for(k,1,n+1) 40 _for(p,j+1,m+1) 41 dp[i][j][k][p] = MightyMaXXX(dp[i-1][j][k-1][p],dp[i][j-1][k-1][p],dp[i-1][j][k][p-1],dp[i][j-1][k][p-1])+a[i][j]+a[k][p]; 42 43 printf("%d ",dp[n][m-1][n-1][m]); 44 return 0; 45 }