-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0018.cpp
43 lines (37 loc) · 974 Bytes
/
0018.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
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <functional>
void fn0() {
std::vector<std::vector<int>> triangle;
// read in the triangle
std::fstream in("0018.txt");
for (int j = 1; ;j++) {
std::vector<int> x;
for (int i = 0; i < j; i++) {
int n;
in >> n;
if (in.eof()) break;
x.push_back(n);
//std::cout << n << " ";
}
if (in.eof()) break;
//std::cout << std::endl;
triangle.push_back(x);
}
std::vector<int> sum = triangle.back();
triangle.pop_back();
for (auto x = triangle.rbegin(); x != triangle.rend(); x++) {
std::vector<int> tmp;
for (int i = 0; i < (*x).size(); i++) {
int m = std::max((*x)[i] + sum[i], (*x)[i] + sum[i+1]);
//std::cout << m << " ";
tmp.push_back(m);
}
//std::cout << std::endl;
sum = std::move(tmp);
}
std::cout << sum[0] << std::endl;
}
std::vector<std::function<void()>> progs = { fn0 };