HDU 1559 最大子矩阵
最大子矩阵
Time Limit : 30000/10000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
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
Author
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int map[1100][1100];
int temp[1100];
int t;
int n,m,x,y;
int main() {
scanf("%d",&t);
while(t --)
{
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i = 1;i <= n;i ++)
for(int j = 1;j <= m;j ++)
scanf("%d",&map[i][j]);
int max = 0;
for(int i = 1;i <= n - x + 1;i ++)
{
memset(temp,0,sizeof(temp));
for(int j = 1;j <= m;j ++)
{
temp[j] = temp[j - 1];
for(int k = i;k < i + x;k ++)
temp[j] += map[k][j];
}
for(int k = y;k <= m;k ++){
//printf("%d\n",temp[k] - temp[k - y]);
if(temp[k] - temp[k - y] > max)
max = temp[k] - temp[k - y];}
}
printf("%d\n",max);
}
return 0;
}