Posted on 2009-03-22 13:59
superman 阅读(91)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("numtri.in", "r", stdin);
8 freopen("numtri.out", "w", stdout);
9
10 int n;
11 int x[1000][1000] = { 0 };
12 int f[1000][1000] = { 0 };
13
14 cin >> n;
15 for (int i = 0; i < n; i++)
16 for (int j = 0; j <= i; j++)
17 cin >> x[i][j];
18
19 f[0][0] = x[0][0];
20 for (int i = 0; i < n - 1; i++)
21 for (int j = 0; j <= i; j++)
22 {
23 f[i + 1][j] >?= (f[i][j] + x[i + 1][j]);
24 f[i + 1][j + 1] >?= (f[i][j] + x[i + 1][j + 1]);
25 }
26
27 int ans = 0;
28 for (int i = 0; i < n; i++)
29 ans >?= f[n - 1][i];
30
31 cout << ans << endl;
32
33 return 0;
34 }
35