Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2843 Accepted Submission(s): 1431
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 int num[2000][2000]; 7 int ans; 8 int main() 9 { 10 int n,i,j,k,x,y,a,kase,m; 11 scanf("%d",&kase); 12 while(kase--) 13 { 14 scanf("%d %d %d %d",&m,&n,&x,&y); 15 memset(num,0,sizeof(num)); 16 for(i=1;i<=m;i++){ 17 for(j=1;j<=n;j++){ 18 scanf("%d",&a); 19 num[i][j]=num[i][j-1]+a; 20 } 21 } 22 int maxn=-0x3f3f3f3f; 23 for(i=1;i<=m-x;i++) 24 { 25 for(j=1;j<=n-y;j++) 26 { 27 ans=0; 28 for(k=j;k<=j+y-1;k++) 29 ans+=num[k][i+x]-num[k][i]; 30 if(ans>maxn) 31 maxn=ans; 32 } 33 } 34 printf("%d\n",maxn); 35 } 36 return 0; 37 }
HDU 1559 最大子矩阵 (DP),布布扣,bubuko.com
原文:http://www.cnblogs.com/clliff/p/3896094.html