CF1765K.Torus Path

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a square grid with nn rows and nn columns, where each cell has a non-negative integer written in it. There is a chip initially placed at the top left cell (the cell with coordinates (1,1)(1, 1)). You need to move the chip to the bottom right cell (the cell with coordinates (n,n)(n, n)).

In one step, you can move the chip to the neighboring cell, but:

  1. you can move only right or down. In other words, if the current cell is (x,y)(x, y), you can move either to (x,y+1)(x, y + 1) or to (x+1,y)(x + 1, y). There are two special cases:
    • if the chip is in the last column (cell (x,n)(x, n)) and you're moving right, you'll teleport to the first column (to the cell (x,1)(x, 1));
    • if the chip is in the last row (cell (n,y)(n, y)) and you're moving down, you'll teleport to the first row (to the cell (1,y)(1, y)).
  2. you cannot visit the same cell twice. The starting cell is counted visited from the beginning (so you cannot enter it again), and you can't leave the finishing cell once you visit it.

Your total score is counted as the sum of numbers in all cells you have visited. What is the maximum possible score you can achieve?

你被给定一个 nn 行 nn 列的方阵网格,其中每个格子中写有一个非负整数。一枚棋子初始位于左上角格子(坐标为 (1,1)(1, 1) 的格子)。你需要将该棋子移动到右下角格子(坐标为 (n,n)(n, n) 的格子)。

每一步中,你可以将棋子移至一个相邻格子,但需满足以下条件:

  1. 你只能向右或向下移动。换言之,若当前格子为 (x,y)(x, y),则你只能移至 (x,y+1)(x, y + 1) 或 (x+1,y)(x + 1, y)。存在两种特殊情况:
    • 若棋子位于最后一列(即格子 (x,n)(x, n)),且你尝试向右移动,则棋子将传送到第一列(即格子 (x,1)(x, 1));
    • 若棋子位于最后一行(即格子 (n,y)(n, y)),且你尝试向下移动,则棋子将传送到第一行(即格子 (1,y)(1, y))。
  2. 你不能访问同一个格子两次。起始格子从一开始即被视为已访问(因此你不能再进入它),且一旦你访问了终点格子,便不能再离开它。

你的总得分定义为:你所访问过的所有格子中的数字之和。你能获得的最大可能得分是多少?

输入格式

The first line contains the single integer nn (2≤n≤2002 \le n \le 200) — the number of rows and columns in the grid.

Next nn lines contains the description of each row of the grid. The ii-th line contains nn integers ai,1,ai,2,…,ai,na_{i, 1}, a_{i, 2}, \dots, a_{i, n} (0≤ai,j≤1090 \le a_{i, j} \le 10^9) where ai,ja_{i, j} is the number written in the cell (i,j)(i, j).

第一行包含一个整数 nn(2≤n≤2002 \le n \le 200)—— 表示网格的行数与列数。

接下来的 nn 行描述了网格的每一行。第 ii 行包含 nn 个整数 ai,1,ai,2,…,ai,na_{i, 1}, a_{i, 2}, \dots, a_{i, n}(0≤ai,j≤1090 \le a_{i, j} \le 10^9),其中 ai,ja_{i, j} 表示位于第 ii 行第 jj 列的单元格中所写的数字。

输出格式

Print one integer — the maximum possible score you can achieve.

输出一个整数——你能获得的最高可能得分。

输入输出样例

  • 输入#1

    2
    1 2
    3 4

    输出#1

    8
  • 输入#2

    3
    10 10 10
    10 0 10
    10 10 10

    输出#2

    80

输入解题思路,AI测评打分。不知道怎么写?

首页