Describe:
When it comes to the DP algorithm, a classic example is the problem of the tower, which is described in this way:
As shown in the following tower, required to go from the top floor to the bottom, if each step can only go to adjacent nodes, then the number of nodes through the sum of the maximum is how much?
Code:
#include <stdio.h>#include<string.h>#include<iostream>#include<stdlib.h>#include<math.h>#defineN 105using namespacestd;intHeight,tree[n][n],dp[n][n];intMain () {inttestcase; scanf ("%d",&testcase); while(testcase--) {scanf ("%d",&height); Memset (DP,0,sizeof(DP)); for(intI=0; i ){ for(intj=0; j<i+1; j + +) {scanf ("%d",&Tree[i][j]); } } for(inti=height-1; i>=0; i-- ){ for(intj=0; j<i+1; j + +) {Dp[i][j]=tree[i][j]+max (dp[i+1][j],dp[i+1][j+1]); }} printf ("%d\n", dp[0][0]); } System ("Pause"); return 0;}
hdu2084-Number Tower