47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int DEPTH = 100;
|
|
|
|
int main(){
|
|
|
|
cout << "Hello this is Patrick" << endl;
|
|
auto start = chrono::high_resolution_clock::now();
|
|
|
|
int c;
|
|
ifstream triangleFile("../txts/p067_triangle.txt");
|
|
|
|
vector<vector<int>> triangle(DEPTH);
|
|
for(int i = 0; i < DEPTH; ++i){
|
|
for(int j = 0; j <= i; ++j){
|
|
triangleFile >> c;
|
|
triangle[i].push_back(c);
|
|
}
|
|
}
|
|
|
|
// Checking if it reads correctly, which it did on the first try yey
|
|
// for(auto row : triangle){
|
|
// for(auto n : row){
|
|
// cout << n << " ";
|
|
// }
|
|
// cout << endl;
|
|
// }
|
|
|
|
|
|
vector<vector<int>> maxima(DEPTH);
|
|
maxima[DEPTH - 1] = triangle[DEPTH - 1];
|
|
|
|
for(int i = DEPTH - 2; i >= 0; --i){
|
|
for(int j = 0; j <= i; ++j){
|
|
maxima[i].push_back(max(maxima[i + 1][j], maxima[i + 1][j + 1]) + triangle[i][j]);
|
|
}
|
|
}
|
|
|
|
cout << maxima[0][0] << endl;
|
|
|
|
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
|
|
cout << (float)duration.count()/1000 << endl;
|
|
return 0;
|
|
}
|