1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Scanner input = new Scanner(System.in); 8 int n = input.nextInt(); 9 int [][]a=new int [n][n]; 10 for(int i = 0;i<n;i++) { 11 for(int j = 0;j <= i;j++ ) { 12 a[i][j] =input.nextInt(); 13 } 14 } 15 System.out.println(add(a,n)); 16 input.close(); 17 18 } 19 public static int add(int [][]b,int n) { 20 for(int i = n-2;i>=0;i--) { 21 for(int j = 0;j <= i;j++ ) { 22 b[i][j]+=max(b[i+1][j],b[i+1][j+1]); 23 } 24 }//这里从下向上进行判定。不然从上向下的还要进行再次比较大小。 25 return b[0][0]; 26 27 } 28 public static int max (int a,int b) { 29 if(a>b)return a; 30 else return b; 31 } 32 33 }