When talking about the DP algorithm, a classic example is the data tower problem, which is described as follows:
There is a number tower as shown below. It is required to go from the top layer to the bottom layer. If each step can only go to adjacent nodes, what is the maximum sum of the numbers of the nodes that pass through?
I already told you that this is a DP question. Can you AC it?
Input
The input data first includes an integer C, indicating the number of test instances. The first row of each test instance is an integer N (1 <= N <= 100 ), the height of the tower. Next, use N rows of numbers to represent the tower. Row I has an I integer, and All integers are within the range [0, 99.
Output
For each test instance, the output is the largest possible sum, and each instance occupies one row of output.
Sample Input
1
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30 # include <stdio. h> num [] [scanf (, & (c -- scanf (, & (I =; I <n; I ++ (j =; j <= I; j ++ scanf (, & (I = n-; I>-; I -- (j =; j <= I; j ++ (num [I +] [j]> num [I +] [j + num [I] [j] + = num [I + num [I] [j]] + = num [I +] [j + printf (, num [] [}View Code