21798_War

2022-5-16 18:20| 发布者: Hocassian| 查看: 23| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505858698700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21798

Title

War

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21798

AC

9

Submit

34

Ratio

26.47%

时间&空间限制

  • Time Limit: 20000/10000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Country X is under attack by enemies. Now the army of enemy has arrived at City Y. City Y consists of an N×M grid. All the paths in the grid are bidirectional, horizontal or vertical or diagonal. The upper-left corner is (0, 0) and lower-right corner is (N, M). The army enters at (0, 0) and they must get to (N, M) in order to continue their attack to the capital of Country X. The figure below shows what does City Y looks like.

    Every blackened node represents a vertex. The number beside each edge is the amount of TNT needed to destroy that road. The army of Country X is unable to beat the enemy now. The only thing they can do is to prevent them from heading to their capital so that they can have more time to prepare for striking back. Of course they want to use the least amount of TNT to disconnect (0, 0) and (N, M). You are a talented programmer, please help them decide the least amount needed.

    输入

    There are multiple test cases.

    The first line of each test case contains two positive integers N and M, representing height and width of the grid.

    Then N+1 lines each containing M integers, giving you the amount needed of horizontal roads in row major order.

    Then N lines each containing M+1 integers, giving you the amount needed of vertical roads in row major order.

    Then 2N lines each containing 2M integers, giving you the amount needed of diagonal roads in row major order.

    There is a blank line after each input block. The sample input is corresponding to the figure above.

    Restriction:

    1 ≤ N, M ≤ 500

    1 ≤ amount ≤ 1000000

    输出

    Description

    Country X is under attack by enemies. Now the army of enemy has arrived at City Y. City Y consists of an N×M grid. All the paths in the grid are bidirectional, horizontal or vertical or diagonal. The upper-left corner is (0, 0) and lower-right corner is (N, M). The army enters at (0, 0) and they must get to (N, M) in order to continue their attack to the capital of Country X. The figure below shows what does City Y looks like.

    Every blackened node represents a vertex. The number beside each edge is the amount of TNT needed to destroy that road. The army of Country X is unable to beat the enemy now. The only thing they can do is to prevent them from heading to their capital so that they can have more time to prepare for striking back. Of course they want to use the least amount of TNT to disconnect (0, 0) and (N, M). You are a talented programmer, please help them decide the least amount needed.

    Input

    There are multiple test cases.

    The first line of each test case contains two positive integers N and M, representing height and width of the grid.

    Then N+1 lines each containing M integers, giving you the amount needed of horizontal roads in row major order.

    Then N lines each containing M+1 integers, giving you the amount needed of vertical roads in row major order.

    Then 2N lines each containing 2M integers, giving you the amount needed of diagonal roads in row major order.

    There is a blank line after each input block. The sample input is corresponding to the figure above.

    Restriction:

    1 ≤ N, M ≤ 500

    1 ≤ amount ≤ 1000000

    Output

    One line for each test case the least amount of TNT needed to disconnect (0, 0) and (N, M).

    Sample Input

    2 3
    1 9 4
    1 8 7
    6 2 3
    7 5 4 8
    6 2 8 7
    10 4 1 7 5 3
    5 4 10 2 1 9
    6 3 2 9 5 3
    8 9 6 3 10 10

    Sample Output

    18

    Source

    样例输入

    2 3
    1 9 4
    1 8 7
    6 2 3
    7 5 4 8
    6 2 8 7
    10 4 1 7 5 3
    5 4 10 2 1 9
    6 3 2 9 5 3
    8 9 6 3 10 10

    样例输出

    18

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部