HDACM2084
此题从最底层开始着手,先求左右两个值的最大值,然后与上面一层的值相加并覆盖,依次类推,最后最上层的必定是最大值
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc =new Scanner(System.in);int c = sc.nextInt();while(c-->0){int n = sc.nextInt();int[][] an = new int[n][];for (int i = 0; i < an.length; i++) {an[i] = new int[i+1];}for (int i = 0; i < an.length; i++) {for (int j = 0; j < an[i].length; j++) {an[i][j]=sc.nextInt();}}for (int i = an.length-1; i>0; i--) {for (int j = 0; j < an[i].length-1; j++) {an[i-1][j] += an[i][j]>an[i][j+1]?an[i][j]:an[i][j+1];}}System.out.println(an[0][0]);}}
}