标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8947 Accepted Submission(s):
4323
#include<stdio.h> #include<string.h> #define N 110 int a[N][N]; int dp(int b[],int n) { int sum=0; int max=0; for(int i=0;i<n;i++) { sum+=b[i]; if(sum<0) { sum=0; } max=max>sum?max:sum; } return max; } int main() { int n; int b[N]; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%d",&a[i][j]); } } int max=0,sum; for(int i=0;i<n;i++) { memset(b,0,sizeof(b)); for(int j=i;j<n;j++) { for(int k=0;k<n;k++) { b[k]+=a[j][k]; } sum=dp(b,n); max=max>sum?max:sum; } } printf("%d\n",max); } return 0; } //矩阵压缩 //将i~j行压缩成一行,存在b[]中,然后求 数组b[]的最大值。
标签:
原文地址:http://www.cnblogs.com/qianyanwanyu--/p/4376982.html