http://tyvj.cn/p/1011
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 50 + 1;
const int maxm = 50 + 1;
int map[maxm][maxn];
int f[maxm][maxn][maxm][maxn];
//设f[i][j][l][k]为第一条路径到达i,j,第二条路径到达l,k的最大值,(i≠l, l≠k)
/*f[i][j][l][k] = max{f[i-1][j][l-1][k],
f[i-1][j][l][k-1],
f[i][j-1][l-1][k],
f[i][j-1][l][k-1]}
*/
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", &map[i][j]);
}
memset(f, 0, sizeof(f));
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
for (int l=1;l<=n;l++)
for (int k=1;k<=m;k++)
{
if ((i!=l&&j!=k)||(i==n&&j==m&&l==n&&k==m))
{
f[i][j][l][k] = max(f[i][j][l][k], f[i-1][j][l-1][k]);
f[i][j][l][k] = max(f[i][j][l][k], f[i-1][j][l][k-1]);
f[i][j][l][k] = max(f[i][j][l][k], f[i][j-1][l-1][k]);
f[i][j][l][k] = max(f[i][j][l][k], f[i][j-1][l][k-1]);
f[i][j][l][k] += map[i][j]+map[l][k];
}
}
printf("%d\n", f[n][m][n][m]);
return 0;
}