For this problem you are given an \$n \times n\$ matrix of integers. The task is to find a pentagon in the matrix with maximum sum. The pentagon must include part (or all) of the x and y axes as two of its sides starting from the top left cell.
All the sides except one must be horizontal or vertical. The remaining side is at 45 degrees ( that is it goes up one for each step to the right).
This picture shows a matrix with a pentagonal part shaded.
Either one or two of the sides can have length zero, as in this example where two zero length sides have turned the pentagon into a triangle. This is an optimal triangular solution for this matrix but may not be an optimal pentagon.
Or this example where one zero-length side has turned a pentagon into a rectangle. This happens to be the optimal rectangle but may not be an optimal pentagon.
[[ 3 0 2 -3 -3 -1 -2 1 -1 0]
[-1 0 0 0 -2 -3 -2 2 -2 -3]
[ 1 3 3 1 1 -3 -1 -1 3 0]
[ 0 0 -2 0 2 1 2 2 -1 -1]
[-1 0 3 1 1 3 -2 0 0 -1]
[-1 -1 1 2 -3 -2 1 -2 0 0]
[-3 2 2 3 -2 0 -1 -1 3 -2]
[-2 0 2 1 2 2 1 -1 -3 -3]
[-2 -2 1 -3 -2 -1 3 2 3 -3]
[ 2 3 1 -1 0 1 -1 3 -2 -1]]
The winning criterion is asymptotic time complexity. E.g. \$O(n^2)\$ time.