hdu 1559(最大子矩阵)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559

思路:感觉就是1081这题差不多,但就是加了一个限制条件。。。

View Code
 1 #include<iostream>
 2 #include<algorithm>
 3 const int N=1010;
 4 using namespace std;
 5 
 6 int map[N][N];
 7 
 8 int main(){
 9     int _case;
10     scanf("%d",&_case);
11     while(_case--){
12         int m,n,x,y;
13         scanf("%d%d%d%d",&m,&n,&x,&y);
14         for(int i=1;i<=m;i++){
15             for(int j=1;j<=n;j++){
16                 scanf("%d",&map[i][j]);
17             }
18         }
19         int ans=0;
20         for(int i=1;i<=m;i++){
21             for(int j=1;j<=n;j++){
22                 map[i][j]+=map[i][j-1]+map[i-1][j]-map[i-1][j-1];
23                 if(i>=x&&j>=y){
24                     int tmp=map[i][j]-map[i-x][j]-map[i][j-y]+map[i-x][j-y];
25                     if(tmp>ans)ans=tmp;
26                 }
27             }
28         }
29         printf("%d\n",ans);
30     }
31     return 0;
32 }

 

posted @ 2013-03-15 19:15  ihge2k  阅读(421)  评论(0编辑  收藏  举报