http://acm.hdu.edu.cn/showproblem.php?pid=1559
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1001
using namespace std;
int b[maxn][maxn];
int a[maxn][maxn];
int dp[maxn];
int n,m,x,y;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i=1; i<=n; i++)
{
b[i][0]=0;
for(int j=1; j<=m; j++)
{
scanf("%d",&a[i][j]);
b[i][j]=b[i-1][j]+a[i][j];
}
}
int max1=-100;
for(int i=x; i<=n; i++)
{
memset(dp,0,sizeof(dp));
for(int j=1; j<=m; j++)
{
dp[j]=b[i][j]-b[i-x][j];
dp[j]=dp[j]+dp[j-1];
if(j>=y)
max1=max(max1,dp[j]-dp[j-y]);
}
}
printf("%d\n",max1);
}
return 0;
}