|
ShutaTime Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/others) total submission (s): 22693 accepted submission (s): 13679When Problem description describes 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 data first includes an integer c, indicating the number of test instances. The first line 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 may be the largest sum, and the output of each instance occupies one row. Sample input1573 88 1 0 2 7 4 44 5 2 6 5 sample output30 |
# Include <stdio. h> # include <stdlib. h> # include <string. h> int C, N, a [110] [110]; int Max _ (int A, int B) {return (A> = B )? A: B;} int main () {int I, j, Max; scanf ("% d", & C); While (c --) {scanf ("% d", & N); max =-99999999; memset (A, 0, sizeof (a); for (I = 1; I <= N; I ++) {for (j = 1; j <= I; j ++) scanf ("% d", & A [I] [J]);} /// if you forget to consider only one case and the first case is not processed, max = A [1] [1]; for (I = 2; I <= N; I ++) // consider the minimum data size for the write range {for (j = 1; j <= I; j ++) {A [I] [J] + = max _ (a [I-1] [J-1], a [I-1] [J]); if (max <A [I] [J]) max = A [I] [J] ;}} printf ("% d \ n", max );} return 0;} // no problem in the intermediate condition. The minimum data condition is incorrect.
DP little dish count Tower