• [B] The Waterfall Flow

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • The Hero is on the way to beat the Devil, now he comes near to a waterfall flow.
    The Devil puts a magic on the waterfall flow in order to stop the Hero.

    The magic makes the waterfall flow come into being m * n (m lows and n columns) blocks, each block is bound with a number Hi, it means that if the Hero comes into that block, he will be injured by Hi HP.

    Now, the Hero wants to kill the Devil, he must go from the foot of the waterfall flow to the top of it. The Hero can choose one of n foot blocks to selected as the starting point, and he can only go upward and towards the left, as well as the right.

    To kill the Devil, he must left more and more HP, can you help him?

  • 输入
  • Input until EOF.
    Each test will contain two integers m and n (3 <= m, n <= 20), and a m * n matrix. The matrix includes m * n integers Hi (1 <= Hi <= 1000).
  • 输出
  • A line includes a integer with the injured HP.
  • 样例输入
  • 4 3
    1 2 3
    4 5 6
    7 8 9
    10 11 12
    4 3
    1000 1000 1
    1 1 1
    1 1000 1000
    1 1 1
    
  • 样例输出
  • 22
    6
    
  • 提示
  • 来源
  • Hungar
  • 操作

显示春菜