QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#11570. 公交车之旅

统计

Byteasar 是 Byteburg 一所小学的老师。最近天气非常好,Byteasar 想带他的班级去 Byteland 的首都 Bytetown 进行一次巴士旅行。Byteasar 决定聘请一家旅行社来规划行程。

Bytetown 的街道构成了一个东西向和南北向街道的规则网格。任意两条相邻平行街道之间的距离为 1 公里。在一些路口坐落着旅游景点。Bytean 的导游为每个旅游景点分配了一个吸引力系数:吸引力越大,景点对游客就越有吸引力。Byteasar 知道他班上的学生很容易感到厌倦,因此他要求行程中参观的景点吸引力必须是严格递增的。

旅行社同意了 Byteasar 的要求。此外,旅行社希望在组织行程时尽可能多地赚钱。旅行社对行程的每一公里收取 1 bythaler 的固定费用。巴士在行程中的景点之间行驶时,总是选择 Bytetown 街道上的最短路径。此外,旅行社还能从行程中参观的景点经理那里获得额外收入。

请帮助旅行社规划一次既满足 Byteasar 的要求,又能为旅行社带来最高利润的行程。请注意,路过一个旅游景点(而不停留)不算作参观该景点。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($2 \le n, m \le 1000$),分别表示东西向街道的数量和南北向街道的数量。

接下来 $n$ 行描述了 Bytetown 的旅游景点。其中第 $i$ 行包含 $m$ 个整数 $w_{i,j}$ ($0 \le w_{i,j} \le 10^6$),给出了位于第 $i$ 条东西向街道与各条南北向街道交汇处的景点的吸引力。吸引力为 0 表示该路口没有旅游景点。你可以假设 Bytetown 至少有一个旅游景点。

接下来 $n$ 行,每行包含 $m$ 个整数 $c_{i,j}$ ($0 \le c_{i,j} \le 10^9$)。其中第 $i$ 行的第 $j$ 个数 $c_{i,j}$ 表示旅行社因行程经过吸引力为 $w_{i,j}$ 的景点而获得的金额(以 bythaler 为单位)。如果某个路口没有旅游景点,则对应的数字 $c_{i,j}$ 等于 0。

输出格式

输出仅包含一个整数:旅行社组织一次经过一系列吸引力严格递增的景点的行程所能获得的最大利润(以 bythaler 为单位)。

样例

输入 1

4 5
1 2 6 0 2
1 3 4 0 4
0 0 4 0 3
2 2 0 0 4
1 3 5 0 2
2 8 1 0 2
0 0 3 0 4
0 5 0 0 3

输出 1

39

说明 1

路口处的数字代表相应景点的吸引力。斜体数字代表旅行社因行程经过相应景点而获得的利润。旅行社利润最高的行程已用圆圈标出:旅行社分别从这些景点获得了 2、2、8 和 5 bythalers 的收入,此外还获得了 19 bythalers 的巴士车费。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.