题目链接:
#include#include #define max(a,b) a>b?a:bint d[1005][1005];int main(){ int T,n,m,x,y,i,j; scanf("%d",&T); while(T--) { scanf("%d%d%d%d",&n,&m,&x,&y); memset(d,0,sizeof(d)); int maxx = -1; for(i = 1 ; i <= n ; i ++) for(j = 1 ; j <= m ; j ++) { scanf("%d",&d[i][j]); d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];//d[i][j]表示这个点之前所有点的和 if(i >= x && j >= y) maxx = max(maxx,d[i][j] - d[i - x][j] - d[i][j - y] + d[i - x][j - y]); } printf("%d\n",maxx); } return 0;}