最大子矩阵

http://acm.hdu.edu.cn/showproblem.php?pid=1559

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[1005][1005];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int m,n,x,y;
        int i,j;
        scanf("%d%d%d%d",&m,&n,&x,&y);
        memset(dp,0,sizeof(dp));
        int maxn=-1;
        for( i=1;i<=m;i++)
            for( j=1;j<=n;j++)
            {
                scanf("%d",&dp[i][j]);
                dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
                if(i>=x&&j>=y)
                    maxn=max(maxn,dp[i][j]-dp[i-x][j]-dp[i][j-y]+dp[i-x][j-y]);
            }
        printf("%d
",maxn);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/lyf123456/p/3441849.html