标签:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 501 int a[N][N]; int n,m; int sub_sum(int *b) { int s,max; s = max = b[1]; int i; for(i=2;i<=n;i++) { s += b[i]; if(s > max) max = s; if(s < 0) s = 0; } return max; } int main() { int i,j,t,maxsum,s; int *b; scanf("%d%d",&n,&m); b = (int *)malloc(sizeof(int)*(n+1)); for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); } maxsum = a[1][1]; for(i=1;i<=m;i++) { memset(b,0,(n+1)*sizeof(int)); for(j=i;j<=m;j++) { //固定i,j列 for(t=1;t<=n;t++) b[t] += a[t][j];//自底向上(固定列m,m,n(固定行n,n,m)) s = sub_sum(b); if(s > maxsum) maxsum = s; } } printf("%d\n",maxsum); return 0; }
标签:
原文地址:http://www.cnblogs.com/520xiuge/p/5461347.html