CF213C.Relay Race

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n × n cells (represented as unit squares), each cell has some number.

At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.

To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.

Print the maximum number of points Furik and Rubik can earn on the relay race.

弗里克和鲁比克参加一场接力赛。比赛将在一个边长为 nn 米的大正方形场地上进行。该正方形被划分为 n×nn \times n 个单元格(即单位正方形),每个单元格中有一个数字。

比赛开始时,弗里克位于坐标为 (1,1)(1, 1) 的单元格,鲁比克位于坐标为 (n,n)(n, n) 的单元格。起跑后,弗里克立即朝鲁比克方向奔跑;若弗里克当前位于坐标为 (i,j)(i, j) 的单元格,则他只能移动到 (i+1,j)(i+1, j) 或 (i,j+1)(i, j+1) 对应的单元格。当弗里克到达鲁比克所在位置后,鲁比克从坐标为 (n,n)(n, n) 的单元格出发,向坐标为 (1,1)(1, 1) 的单元格奔跑;若鲁比克当前位于坐标为 (i,j)(i, j) 的单元格,则他只能移动到 (i−1,j)(i-1, j) 或 (i,j−1)(i, j-1) 对应的单元格。弗里克和鲁比克均不得越出场地边界;若某选手越界,则会被取消资格。

为赢得比赛,弗里克和鲁比克需尽可能多地获取分数。总分数等于两人所经过的所有单元格中的数字之和;每个单元格仅计入一次(即若两人均经过同一单元格,该单元格的数值只加一次)。

请输出弗里克和鲁比克在接力赛中能获得的最大分数。

输入格式

The first line contains a single integer (1 ≤ n ≤ 300). The next n lines contain n integers each: the j-th number on the i-th line a__i, j ( - 1000 ≤ a__i, j ≤ 1000) is the number written in the cell with coordinates (i, j).

第一行包含一个整数 $ n (( 1 \leq n \leq 300 $)。接下来的 $ n $ 行每行包含 $ n $ 个整数:第 $ i $ 行的第 $ j $ 个数 $ a_{i,j} (( -1000 \leq a_{i,j} \leq 1000 $)表示坐标为 $ (i, j) $ 的格子中所写的数字。

输出格式

On a single line print a single number — the answer to the problem.

在一行中输出一个数字——该问题的答案。

输入输出样例

  • 输入#1

    1
    5

    输出#1

    5
  • 输入#2

    2
    11 14
    16 12

    输出#2

    53
  • 输入#3

    3
    25 16 25
    12 18 19
    11 13 8

    输出#3

    136

说明/提示

Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).

Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:

Furik's path is marked with yellow, and Rubik's path is marked with pink.

第二个样例的说明:Furik 的盈利路径为:(1, 1)、(1, 2)、(2, 2);Rubik 的路径为:(2, 2)、(2, 1)、(1, 1)。

第三个样例的说明:Furik 的最优路径为:(1, 1)、(1, 2)、(1, 3)、(2, 3)、(3, 3);Rubik 的路径为:(3, 3)、(3, 2)、(2, 2)、(2, 1)、(1, 1)。该样例对应的图示如下:

Furik 的路径用黄色标出,Rubik 的路径用粉色标出。

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

首页