#P16772. [GKS 2020 #G] Maximum Coins

    ID: 17033 Type: RemoteJudge 3000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>贪心2020枚举Google Kick Start

[GKS 2020 #G] Maximum Coins

题目描述

Mike has a square matrix with NN rows and NN columns. Cell (i,j)(i,j) denotes the cell present at row ii and column jj. Cell (1,1)(1,1) denotes the top left corner of the matrix. Each cell has some amount of coins associated with it and Mike can collect them only if he visits that cell. Ci,jC_{i,j} represents the number of coins in cell with row ii and column jj. From a cell (i,j)(i,j), Mike can decide to go to cell (i+1,j+1)(i+1,j+1) or cell (i−1,j−1)(i-1,j-1), as long as the cell lies within the boundaries of the matrix and has not been visited yet. He can choose to start the journey from any cell and choose to stop at any point. Mike wants to maximize the number of coins he can collect. Please help him determine the maximum number of coins he can collect.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the integer NN. The next NN lines contain NN integers each. The jj-th integer in the ii-th line represents the number of coins Ci,jC_{i,j} in cell (i,j)(i,j).

输出格式

For each test case, output one line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the maximum number of coins Mike can collect.

2
3
1 2 5
3 6 1
12 2 7
5
0 0 0 0 0
1 1 1 1 0
2 2 2 8 0
1 1 1 0 0
0 0 0 0 0
Case #1: 14
Case #2: 9

提示

In Sample Case #11, the maximum number of coins collected can be 1414, if Mike follows this path:

(1,1)→(2,2)→(3,3)(1,1) \to (2,2) \to (3,3)

In Sample Case #22, the maximum number of coins collected can be 99, if Mike follows this path:

(2,3)→(3,4)(2,3) \to (3,4).

Limits

1≤T≤1001 \le T \le 100.

0≤Ci,j≤1070 \le C_{i,j} \le 10^7.

Test Set 11

1≤N≤1001 \le N \le 100.

Test Set 22

1≤N≤1031 \le N \le 10^3 in at most 1010 cases.

1≤N≤1001 \le N \le 100 in all other cases.