思想
java 代码
import java.io.*;
import java.lang.*;
class Main{
static int n = 0, N = 510;
static int[][] a = new int[N][N], f = new int[N][N];
public static void main(String[] args)throws Exception{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
n = Integer.valueOf(buf.readLine());
for(int i = 1; i <= n; ++i){
String[] info = buf.readLine().split(" ");
for(int j = 1; j <= i; ++j){
a[i][j] = Integer.valueOf(info[j - 1]);
}
}
for(int i = n - 1; i >= 0;--i){
for(int j = 1; j <= i + 1; ++j){
a[i][j] = Math.max(a[i + 1][j], a[i + 1][j + 1]) + a[i][j];
}
}
System.out.print(a[1][1]);
}
}