题目链接:http://lightoj.com/volume_showproblem.php?problem=1036
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxn = ; int m,n;
int dp[maxn][maxn][];
int leftsum[maxn][maxn],upsum[maxn][maxn]; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
for(int cas=;cas<=T;cas++){
cin>>m>>n;
for(int i=;i<=m;i++) upsum[][i] = ;
for(int i=;i<=n;i++) leftsum[i][] = ;
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
int a;
scanf("%d",&a);
leftsum[i][j] = leftsum[i][j-] + a;
}
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
int a;
scanf("%d",&a);
upsum[i][j] = upsum[i-][j] + a;
}
memset(dp,,sizeof(dp));
for(int sum=;sum<=m+n;sum++){
for(int i=;i<=sum-;i++){
int j = sum - i;
if(i>m || j>n) continue;
dp[i][j][] = max(dp[i][j-][],dp[i][j-][]) + upsum[i][j];
dp[i][j][] = max(dp[i-][j][],dp[i-][j][]) + leftsum[i][j];
}
}
int ans = max(dp[m][n][],dp[m][n][]);
printf("Case %d: %d\n",cas,ans);
}
}