经典问题,数字金字塔。
倒着求一编
**import java.io.*;
class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(System.out);
static int N = 510;
static int n;
static int a[][] = new int[N][N];
public static void main(String[] args) throws IOException {
String []s = br.readLine().split(" ");
n = Integer.parseInt(s[0]);
for (int i = 1; i <= n; i++) {
s = br.readLine().split(" ");
for (int j = 1; j <= i; j++)
a[i][j] = Integer.parseInt(s[j - 1]);
}
for (int i = n - 1; i > 0; i--) {
for (int j = 1; j <= i; j++) {
a[i][j] += Math.max(a[i + 1][j], a[i + 1][j + 1]);
}
}
pw.println(a[1][1]);
pw.flush();
pw.close();
br.close();
}
}