-
Notifications
You must be signed in to change notification settings - Fork 1
/
Number Triangles.cpp
55 lines (52 loc) · 1.09 KB
/
Number Triangles.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
47
48
49
50
51
52
53
54
55
/*
ID: zdzapple
LANG: C++
TASK: numtri
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <climits>
#include <fstream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;
using namespace std;
ifstream fin ("numtri.in");
ofstream fout ("numtri.out");
int main()
{
int row;
fin >> row;
vector<int> sum(row + 1, 0);
vector<int> sum2(row + 1, 0);
for (int i = 1; i <= row; ++ i)
{
for (int j = 1; j <= i; ++ j)
{
fin >> sum2[j];
}
for (int j = i; j >= 1; -- j)
{
if (j == 1) {
sum[j] += sum2[j];
} else if (j == i) {
sum[j] = sum[j - 1] + sum2[j];
} else {
sum[j] = max(sum[j], sum[j-1]) + sum2[j];
}
}
}
int result = INT_MIN;
for (int i = 1; i <= row; ++i)
if (result < sum[i])
result = sum[i];
fout << result << endl;
return 0;
}