传纸条
#include<bits/stdc++.h> using namespace std; //和方格取数一样,一来一回可以看成走两次 int a[51][51],m,n,dp[51][51][51][51]={0}; int main() { cin>>m>>n; for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) cin>>a[i][j]; for( int x1 = 1; x1 <= m; x1++ ) { for( int y1 = 1; y1 <= n; y1++ ) { for( int x2 = 1; x2 <= m; x2++ ) { for( int y2 = 1; y2 <= n; y2++ ){ int t=max(dp[x1-1][y1][x2-1][y2],dp[x1][y1-1][x2][y2-1]); t=max(t,dp[x1-1][y1][x2][y2-1]); t=max(t,dp[x1][y1-1][x2-1][y2]); if(x1==x2&&y1==y2) dp[x1][y1][x2][y2]=t+a[x1][y1]; else dp[x1][y1][x2][y2]=t+a[x1][y1]+a[x2][y2]; } } } } cout<<dp[m][n][m][n]<<endl; return 0; }