22715_TheTriangle

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

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

Pro.ID

22715

Title

The Triangle

Title链接

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

AC

1

Submit

16

Ratio

6.25%

时间&空间限制

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

    For her spectacular milk output for the previous month, Farmer John has awarded Bessie a prize -- with a twist.  He has given her a triangular grid with N (1 ≤ N ≤ 700) rows (whose lengths vary from 1 through N, of course). Row i of the the grid has i values labeled vij (-1,000,000,000 ≤ vij ≤ 1,000,000,000) where j is in the range 1..i.

    Bessie chooses a sub-triangle whose side length is at least K (1 ≤ K ≤ 20; 1 ≤ KN) within the triangular grid. The sub-triangle is another triangular grid which might be oriented the same as the original triangle or might be 'upside down' with its shorter rows on the bottom instead of the top.

    After she chooses her sub-triangle, Farmer John will take the average of all the numbers in the sub-triangle, discarding the digits to the right of the decimal point, and give her that many gold coins (or take that many gold coins from her if the number is negative). Naturally, Bessie would like to maximize her prize (or minimize her loss). Help her solve this problem.

    By way of example, Bessie is given this triangular grid with N = 3 rows and must choose a sub-triangle with a side length of at least K = 2. A graphical representation of the triangle is shown below:

       / \
      / 5 \
     /-8  4\
    /2 -3  6\
    ---------

    She could choose any of five valid sub-triangles (one of which is the entire original triangle):

                                                      /\
       / \         / \        / \         / \        /5 \      
      / 5 \       / \5\      / 5 \       / 5/\      /----\    
     /-8  4\     /-8 \4\    /-8  4\     /-8/ 4\    /\-8 4/\
    /2 -3  6\   / 2 -3\6\  /-------\   / 2/-3 6\  / 2\-3/6 \
    ---------   ---------  -2  -3  6   ---------  ----------  
     entire      lower        top          lower     upside
    triangle     left                      right      down

    The one that is lined below is the one with the highest average:

       / \
      / 5/\
     /-8/ 4\
    / 2/-3 6\
    ---------

    The average of this sub-triangle is (4+6-3)/3, which is about 2.3333...; without the fraction, the answer is 2.

    Help Bessie calculate the maximum amount of coins which she could receive.

    输入

    Line 1: Two space-separated integers: N and K

    Lines 2..N+1: Line i+1 will contain i space-separated integers: vij

    输出

    Description

    For her spectacular milk output for the previous month, Farmer John has awarded Bessie a prize -- with a twist.  He has given her a triangular grid with N (1 ≤ N ≤ 700) rows (whose lengths vary from 1 through N, of course). Row i of the the grid has i values labeled vij (-1,000,000,000 ≤ vij ≤ 1,000,000,000) where j is in the range 1..i.

    Bessie chooses a sub-triangle whose side length is at least K (1 ≤ K ≤ 20; 1 ≤ KN) within the triangular grid. The sub-triangle is another triangular grid which might be oriented the same as the original triangle or might be 'upside down' with its shorter rows on the bottom instead of the top.

    After she chooses her sub-triangle, Farmer John will take the average of all the numbers in the sub-triangle, discarding the digits to the right of the decimal point, and give her that many gold coins (or take that many gold coins from her if the number is negative). Naturally, Bessie would like to maximize her prize (or minimize her loss). Help her solve this problem.

    By way of example, Bessie is given this triangular grid with N = 3 rows and must choose a sub-triangle with a side length of at least K = 2. A graphical representation of the triangle is shown below:

       / \
      / 5 \
     /-8  4\
    /2 -3  6\
    ---------

    She could choose any of five valid sub-triangles (one of which is the entire original triangle):

                                                      /\
       / \         / \        / \         / \        /5 \      
      / 5 \       / \5\      / 5 \       / 5/\      /----\    
     /-8  4\     /-8 \4\    /-8  4\     /-8/ 4\    /\-8 4/\
    /2 -3  6\   / 2 -3\6\  /-------\   / 2/-3 6\  / 2\-3/6 \
    ---------   ---------  -2  -3  6   ---------  ----------  
     entire      lower        top          lower     upside
    triangle     left                      right      down

    The one that is lined below is the one with the highest average:

       / \
      / 5/\
     /-8/ 4\
    / 2/-3 6\
    ---------

    The average of this sub-triangle is (4+6-3)/3, which is about 2.3333...; without the fraction, the answer is 2.

    Help Bessie calculate the maximum amount of coins which she could receive.

    Input

    Line 1: Two space-separated integers: N and K

    Lines 2..N+1: Line i+1 will contain i space-separated integers: vij

    Output

    Line 1: The maximum number of coins that Bessie can receive (or, if negative, the best she can do for her loss).

    Sample Input

    3 2
    5
    -8 4
    2 -3 6

    Sample Output

    2

    Source

    样例输入

    3 2
    5
    -8 4
    2 -3 6

    样例输出

    2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部