您的位置:首页 > 其它

hdu 1559 最大子矩阵 (简单dp)

2014-02-26 17:08 351 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1559

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000+10;
const int INF = 1<<28;
int map[maxn][maxn];  //表示以[1,1]为左上角,以[i,j]为右下角的矩形的和

int main()
{
int t, i, j, m, n, x, y;
int s1, sc, Max, ans;
scanf("%d", &t);
while(t--)
{
memset(map, 0, sizeof(map));
Max = -INF;
scanf("%d%d%d%d", &m, &n, &x, &y);
for(i = 1; i <= m; i++)
{
s1 = 0;
for(j = 1; j <= n; j++)
{
scanf("%d", &sc);
s1 += sc;
map[i][j] = s1+map[i-1][j];
}
}
for(i = 1; i <= m; i++)
for(j = 1; j <= n; j++)
if((i+x-1)<=m && (j+y-1)<=n)
{
ans = map[i+x-1][j+y-1]-map[i+x-1][j-1]-map[i-1][j+y-1]+map[i-1][j-1];//减出来就是以[i,j]
//为左顶点,大小为xy的矩形的和
if(Max < ans)
Max = ans;
}
printf("%d\n", Max);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: