cogs 997. [東方S2] 射命丸文

二次联通门 : cogs 997. [東方S2] 射命丸文

 

 

 

 

/*
    cogs 997. [東方S2] 射命丸文
    
    二维前缀和
    枚举每个子矩阵
    更新最大值。。 
    
    莫名rank1 
*/
#include <cstdio>

void read (int &now)
{
    register char word = getchar ();
    for (now = 0; word < '0' || word > '9'; word = getchar ());
    for (; word >= '0' && word <= '9'; now = now * 10 + word - '0', word = getchar ());
}

int N, M, R, C;
#define Max 1020

long long sum[Max][Max];

inline long long max (long long a, long long b)
{
    return a > b ? a : b;
}

int main (int argc, char *argv[])
{
    freopen("aya.in","r",stdin);
    freopen("aya.out","w",stdout);
    read (N);
    read (M);
    read (R);
    read (C);

    int x;
    for (register int i = 1, j; i <= N; i ++)
        for (j = 1; j <= M; j ++)
        {
            read (x);
            sum[i][j] = sum[i][j - 1] + sum[i - 1][j] + x - sum[i - 1][j - 1];
        }

    long long Answer = -1;
    for (register int i = R, j; i <= N; i ++)
        for (j = C; j <= M; j ++)
            Answer = max (Answer, sum[i][j] - sum[i - R][j] - sum[i][j - C]+ sum[i - R][j - C]);
    printf ("%d", Answer);
    return 0;
}

 

posted @ 2017-07-17 11:07  ZlycerQan  阅读(316)  评论(0编辑  收藏  举报