HDU 1181


#include <stdio.h>  
#include <string.h>  
  
int main()  
{ 
	freopen("1081.txt","r",stdin);
    const int size = 101;  
    int Max,sum;  
    int N,i,j,k,val,a[size][size];  
    while (scanf("%d",&N)!=EOF)  
    {  
        memset(a,0,sizeof(a));  
        Max = -128;  
        for(i=1;i<=N;i++)  
            for(j=1;j<=N;j++)  
            {  
                scanf("%d",&val);  
                a[i][j]+=a[i][j-1]+val;//a[i][j]表示第i行前j个数之和  
            }  
        for(i=1;i<=N;i++)  
            for (j=i;j<=N;j++)  
                for(sum = 0,k=1;k<=N;k++)  
                {  
                    //a[k][j]-a[k][i-1]表示第k行第j列与第i列之间的数  
                    sum=(sum>0?sum:0)+a[k][j]-a[k][i-1];  
                    if(sum>Max)  
                        Max = sum;  
                }  
        printf("%d\n",Max);  
    }  
}  

你可能感兴趣的:(HDU 1181)