http://acm.hdu.edu.cn/showproblem.php?pid=2084
我是从上往下推所以最后要求最大值 ,如果从下往上的话就直接在第一个位置,不过理解起来是一样的哈!
/*
2011-9-3
author:BearFly1990
*/
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class HDU_2084 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int t,n,m;
t = in.nextInt();
while(t-- > 0){
n = in.nextInt();
int[][] numTower = new int[n+2][n+2];
for(int i = 0; i <=n+1 ; i++){
Arrays.fill(numTower[i], -1);
}
for(int i = 1; i <=n ; i++){
for(int j = 1; j <= i; j++){
int now = numTower[i][j] = in.nextInt();
int tempLeft = numTower[i-1][j-1] + now;
int tempRight = numTower[i-1][j]+now;
numTower[i][j] = Math.max(Math.max(tempLeft, tempRight),now);
}
}
int result = -1;
for(int j = 1; j <= n; j++){
result = Math.max(numTower[n][j], result);
}
System.out.println(result);
}
}
}