11717 - Max Block Sum   

Description

(7 points)
Given an n-by-n square matrix A, divide it into 2-by-2 non-overlapping blocks.
Compute the sum of each 2-by-2 block and find the maximum block sum.

For example, if the square matrix A is
1 2 3 4
5 6 7 8
9 8 7 6
5 4 3 2

There are four non-overlapping 2-by-2 blocks, which are
1 2 
5 6 

3 4
7 8

9 8
5 4

7 6
3 2

The maximum block sum is 26, yielded by the block
9 8
5 4

 

#include <stdio.h>

int main(){
    int A[500][500];
    int ans = 0;

    int n = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            scanf("%d", &A[i][j]);
        }
    }

    /*  Your Code:  */

    printf("%d\n", ans);
    return 0;
}

Input

The first line contains an integer n, representing the size of A. It is guaranteed that 1 <= n <= 500, and n is always a multiple of 2.

The next n lines represent the n rows of A. Each row contains n integers.

The code for reading the input and printing the output is given.

Output

Print the maximum block sum of A.

Remember printing '\n' in the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss