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; }
相关文章推荐
- hdu 1559(简单的dp)最大子矩阵
- HDU 1559 最大子矩阵 (DP)
- HDU 1559 最大子矩阵 (DP)
- HDU 1559 最大子矩阵 (DP)
- HDU 1559 最大子矩阵--dp--(最大和子矩阵模型)
- HDU - 1559 最大子矩阵(dp)
- hdu 1559 最大子矩阵(DP)
- HDU 1559 最大子矩阵(DP)
- HDU 1559 最大子矩阵 (给定大小) DP
- hdu 1559 最大子矩阵(DP)
- HDU 1559 最大子矩阵 (DP)
- hdu 1559【最大子矩阵和DP】
- HDU:1559 最大子矩阵(动态规划DP)
- HDU 1559 最大子矩阵和 (dp) 枚举+dp
- HDU 2870 Largest Submatrix DP求最大子矩阵
- hdu 1081 To The Max ****poj 1050(最大子矩阵和)DP
- HDU 1081 To The Max (DP) 扩展最大子列和,求最大子矩阵和
- HDU 1506 (DP求最大子矩阵)
- HDU 1559 最大子矩阵
- HDU 1559 最大子矩阵