10122_NumberTriangles

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

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

Pro.ID

10122

Title

Number Triangles

Title链接

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

AC

194

Submit

340

Ratio

57.06%

时间&空间限制

  • Time Limit: 600/300 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Consider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.

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

    In the sample above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30.

    输入

    Multiple test cases. For each case :

    The first line contains R (1 ≤ R ≤ 1000), the number of rows. Each subsequent line contains the integers for that particular row of the triangle. All the supplied integers are non-negative and no larger than 100.

    输出

    Description

    Consider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.

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

    In the sample above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30.

    Input

    Multiple test cases. For each case :

    The first line contains R (1 ≤ R ≤ 1000), the number of rows. Each subsequent line contains the integers for that particular row of the triangle. All the supplied integers are non-negative and no larger than 100.

    Output

    For each test case, output a single line containing the largest sum using the traversal specified.

    Sample Input

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

    2
    1
    2 3

    Sample Output

    30
    4

    Source

    样例输入

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

    2
    1
    2 3

    样例输出

    30
    4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部