The Triangle | ||||||
| ||||||
Description | ||||||
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) | ||||||
Input | ||||||
Your program is to read from standard input. For each test case, the first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99. Process to the end of file. | ||||||
Output | ||||||
For each test case, your program is to write to standard output. The highest sum is written as an integer. | ||||||
Sample Input | ||||||
5 | ||||||
Sample Output | ||||||
30
简单的DP题,求从root到达三角形底部的任意一个位置的sum和最大的值。 化为小的问题:(dp[i,j]代表达到第i行第j个数的sum的最大值) 代码:
|
HLG 1004 The Triangle(数塔问题DP)
最新推荐文章于 2018-05-27 00:44:47 发布