Number of towers
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 32087 Accepted Submission (s): 19162
Problem description When it comes to DP algorithms, a classic example is the tower problem, 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?
Already told you, this is a DP problem, can you AC?
Input data first includes an integer c, which indicates the number of test instances, the first line of each test instance is an integer N (1 <= N <= 100), which represents the height of the tower, followed by the number of columns in N rows, where I is an integer in the line I, and all integers are in the interval [ 0,99] inside.
Output for each test instance, the outputs may be the largest and one row per instance output.
Sample Input1573 88 1 0 2 7 4 44 5 2 6 5
Sample Output30
Source 2006/1/15 ACM Program Design Final Exam
Recommendlcy
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intmaxn= the;7 intA[MAXN][MAXN];8 intD[MAXN][MAXN];9 Ten intMain () One { A intT,n; -scanf"%d",&t); - while(t--) the { -scanf"%d",&n); - for(intI=1; i<n;i++) - for(intj=1; j<n;j++) +d[i][j]=0; - for(intI=1; i<=n;i++) + for(intj=1; j<=i;j++) Ascanf"%d",&a[i][j]); at for(intI=1; i<=n;i++) d[n][i]=A[n][i]; - for(inti=n-1; i>=1; i--) - for(intj=1; j<=i;j++) -D[i][j]=a[i][j]+max (d[i+1][j],d[i+1][j+1]); -printf"%d\n", d[1][1]); - } in}
HDU 2084 Number Tower