标签:
zznu 1625
详解链接:http://blog.csdn.net/su20145104009/article/details/51277041
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<cctype> #include<algorithm> #include <vector> #include <queue> using namespace std; #define INF 0x3f3f3f3f #define N 55 int maps[N][N]; int dp[N][N][N][N]; int main() { int T, m, n; scanf("%d", &T); while(T--) { scanf("%d%d", &m, &n); for(int i=1; i<=m; i++) for(int j=1; j<=n; j++) scanf("%d", &maps[i][j]); memset(dp, 0, sizeof(dp)); for(int i=1; i<=m; i++) for(int j=1; j<=n; j++) for(int k=i+1; k<=m; k++) { int l=i+j-k; if(l<0 || l>n) break; dp[i][j][k][l]=max(max(dp[i-1][j][k][l-1], dp[i-1][j][k-1][l]), max(dp[i][j-1][k-1][l], dp[i][j-1][k][l-1]))+maps[i][j]+maps[k][l]; } printf("%d\n", max(max(dp[m-1][n][m][n-1], dp[m-1][n][m-1][n]), max(dp[m][n-1][m-1][n], dp[m][n-1][m-1][n]))+maps[m][n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/9968jie/p/5532638.html