joj2511

 2511: Number triangle

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
1s 65536K 427 217 Standard
        5
      3   4
    8   1   2
  5   4   3   6
2   1   7   9   8

A number trangle is composed of N(N<=100) line numbers, the i-th line contains i positive integers(<=100). A chess can walk from the top line of the triangle to the bottom line. Suppose the chess is on the k-th number of one line, then it can only move to the k-th number or the (k+1)-th number of the line below in one step. Find a path from the top to the bottom, which can maximize the sum of the integers on the path.

Input

There are multiple test cases.For each test case, there's an integer N representing the size of the triangle, followed by N lines of positive intergers, the first line has 1 integer, next has two integers... the Nth line has N integers.

Output

The maximum sum of the integers on the path.

Sample Input

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

Sample Output

16
12

你可能感兴趣的:(Integer,input,Path,each,output,Numbers)