The 51Nod first-level algorithm has a number of 1002 data towers, and the 51nod algorithm has a number of 1002 data towers.
--- Restore content start ---
1 # include <stdio. h> 2 # include <stdlib. h> 3 # define max (x, y) (x)> (y )? (X) :( y) 4 int main () {5 int n; 6 int I, j, k; 7 scanf ("% d", & n ); // Layer 8 k = (n + 1) * n/2; // total number of all nodes 9 int * a = (int *) malloc (sizeof (int) * k ); // dynamic array, record the number of each node 10 for (I = 0; I <k; I ++) {// enter the number of each node 11 scanf ("% d ", & a [I]); 12} 13 k-= n; // The first node of the penultimate layer 14 for (I = K-1, j = 0; I> = 0; I --) {15 a [I] = a [I] + max (a [I + n], a [I + n-1]); // greedy, add the maximum value of the Left or Right node of the lower layer to itself 16 if (+ + j = N-1) {// After traversing the layer, n-117 n --; 18 j = 0; 19} 20} 21 printf ("% d \ n", a [0]); 22 return 0; 23}
Idea: Starting from the penultimate row, add the value of each node to the maximum value of the left and right nodes of the next layer, and traverse the node layer by layer until the vertex ends, and the vertex content is output.
--- Restore content end ---