标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1559
Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3859 Accepted Submission(s): 1967
Sample Input
1
4 5 2 2
3 361 649 676 588
992 762 156 993 169
662 34 638 89 543
525 165 254 809 280
Sample Output
2474
最大子矩阵和问题,与hdu1081相似,这里多了一个规定的子矩阵的范围,所以只要在找子矩阵时保证子矩阵范围是所要求的范围就可以了
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 int a[1100][1100]; 7 int main(){ 8 int n, m, i, j, k, T, x, y; 9 cin>>T; 10 while(T--){ 11 cin>>n>>m; 12 cin>>x>>y; 13 memset(a, 0, sizeof(a)); 14 for(i=1; i<=n; i++){ 15 for(j=1; j<=m; j++){ 16 cin>>a[i][j]; 17 a[i][j] += a[i-1][j]; 18 } 19 } 20 int mmax = -1000000, sum; 21 for(i=x; i<=n; i++){ 22 for(j=1; j<=m-y+1; j++){ 23 sum = 0; 24 for(k=j; k<j+y; k++){ 25 sum += (a[i][k]-a[i-x][k]); 26 } 27 if(sum > mmax) 28 mmax = sum; 29 if(sum < 0) 30 sum = 0; 31 } 32 } 33 cout<<mmax<<endl; 34 } 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/wudi-accept/p/5334342.html