Description
Figure 1 shows a number triangle. Write A program this calculates the highest sum of numbers passed on a route this starts at the top and ends somewhere on The base. Each of the step can go either diagonally down to the left or diagonally down to the right.
Input
Your program was to read from standard input. The first line contains one integer n:the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle are > 1 but <= 100. The numbers in the triangle, all integers, is between 0 and 99.
Output
Your program is-to-write to standard output. The highest sum is a written as an integer.
Sample Input
573 88 1 0 2 7 4 44 5 2 6 5
Sample Output
30
//Do the first DP question, come on
The idea is to create an array that is dynamically planned from the bottom up , saving the maximum value of the page child node to the current node
#include <iostream>#include<cmath>#include<algorithm>#include<cstdio>using namespacestd;intMain () {intdp[102][102]; intN; while(cin>>N) { for(intI=1; i<=n;i++) for(intj=0; j<i;j++) Cin>>Dp[i][j]; for(inti=n-1; i>=1; i--) for(intj=0; j<i;j++) Dp[i][j]+ = max (dp[i+1][j],dp[i+1][j+1]); cout<<dp[1][0]<<Endl; } return 0;}
POJ 1163 the Triangle