链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1081
代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #define max2(a,b) (a>b?a:b) #define N 110 #define INF 0xfffffff int a[N][N], b[N][N][N]; int main() { int n; while(scanf("%d", &n)!=EOF) { int i, j, k, x, max1; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(i=1; i<=n; i++) for(j=1; j<=n; j++) scanf("%d", &a[i][j]); max1=-INF; for(i=1; i<=n; i++) for(j=1; j<=n; j++) for(x=0, k=j; k>0; k--) { x += a[i][k]; b[i][j][k] = max2(b[i][j][k], b[i-1][j][k]) + x; if(b[i][j][k]>max1) max1 = b[i][j][k]; } printf("%d\n", max1); } return 0; }
时间: 2024-11-02 04:59:33