/
numtri.cpp
47 lines (39 loc) · 941 Bytes
/
numtri.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Use the slash-star style comments or the system won't see your
identification information */
/*
ID: yzylive1
TASK: numtri
LANG: C++
*/
/* LANG can be C++20 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <string>
using namespace std;
int tri[1010][1010] = {0};
int main() {
ofstream fout ("numtri.out");
ifstream fin ("numtri.in");
int R;
fin >> R;
for (int i = 1; i <= R; i++) {
for (int j = 0; j < i; j++) {
fin >> tri[i - 1][j];
}
}
for (int i = R - 1; i >= 0; i--) {
for (int j = 0; j <= i; j++) {
int tmp1 = tri[i + 1][j];
int tmp2 = tri[i + 1][j + 1];
int maxTmp = tmp1 > tmp2 ? tmp1 : tmp2;
tri[i][j] += maxTmp;
}
}
fout << tri[0][0] << endl;
return 0;
}