Shuta
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 6182 accepted submission (s): 3633
When 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 Input
1573 88 1 0 2 7 4 44 5 2 6 5
Sample output
30# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Int fun (int x, int y)
{
Return x> Y? X: Y;
}
Int main ()
{
Int C, M;
Scanf ("% d", & C );
While (c --)
{
Scanf ("% d", & M );
Int I, J;
Int A [101] [101];
Memset (A, 0, sizeof ());
For (I = 1; I <= m; I ++)
For (j = 1; j <= I; j ++)
Scanf ("% d", & A [I] [J]);
For (I = M-1; I> = 1; I --)
For (j = 1; j <= I + 1; j ++)
A [I] [J] = fun (A [I] [J] + A [I + 1] [J], A [I] [J] + A [I + 1] [J + 1]);
Printf ("% d \ n", a [1] [1]);
}
System ("pause ");
Return 0;
}
Simple DP, another way of thinking, from the back to the front ..