Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2084
Number of towers
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 32468 Accepted Submission (s): 19417
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 Output30DP Learning 1Dynamic programming (programming) is a branch of operations research and a mathematical method for solving decision-making processes (decision process) optimization. • In a program, it is a method of obtaining (optimal) solutions by setting, saving state and stepwise recursion. From the bottom up, the maximum value of each point equals its own value plus its two child's node maximum, dp[i][j] = max ((Mp[i][j]+dp[i+1][j]), (mp[i][j]+dp[i+1][j+1]), and the following is the code:
1#include <cstdio>2#include <algorithm>3#include <cstring>4 using namespacestd;5 Const intN = the;6 intMp[n][n];7 intDp[n][n];8 intMain ()9 {Ten intT; Onescanf"%d",&t); A while(t--) - { -Memset (DP,0,sizeof(DP)); the intN; -scanf"%d",&n); - for(inti =0; I < n; i++) - for(intj =0; J <= I; J + +) +scanf"%d",&mp[i][j]); - for(inti =0; I < n; i++) dp[n-1][i] = mp[n-1][i]; + for(inti = n2; I >=0; i--) A for(intj =0; J <= I; J + +) atDP[I][J] = max ((mp[i][j]+dp[i+1][J]), (mp[i][j]+dp[i+1][j+1])); -printf"%d\n", dp[0][0]); - } - return 0; -}
~~DP study _1 of the tower