非常简单的动态规划,不说了~~~

/**//*
ID: sdjllyh1
PROG: numtri
LANG: JAVA
complete date: 2008/11/23
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import java.io.*;
import java.util.*;
public class numtri

{
private static int n;
private static int[][] values = new int[1002][1002];
private static int[][] highest = new int[1002][1002];
private static int highestSum = 0;
public static void main(String[] args) throws IOException
{
init();
run();
output();
System.exit(0);
}
private static void run()
{
highest[1][1] = values[1][1];
for (int i = 2; i <= n; i++)
for (int j = 1; j <= i; j++)
{
highest[i][j] = Math.max(highest[i - 1][j], highest[i - 1][j - 1]) + values[i][j];
}
for (int j = 1; j <= n; j++)
{
highestSum = Math.max(highestSum, highest[n][j]);
}
}
private static void init() throws IOException
{
BufferedReader f = new BufferedReader(new FileReader("numtri.in"));
n = Integer.parseInt(f.readLine());
for (int i = 1; i <= n; i++)
{
StringTokenizer st = new StringTokenizer(f.readLine());
for (int j = 1; j <= i; j++)
{
values[i][j] = Integer.parseInt(st.nextToken());
}
}
f.close();
}
private static void output() throws IOException
{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("numtri.out")));
out.println(highestSum);
out.close();
}
}
浙公网安备 33010602011771号