067 pretty easy, just keep track of the maximum routes starting from the bottom

This commit is contained in:
2021-11-13 13:29:55 +01:00
parent 8f5217e793
commit 0e1b0de59f
2 changed files with 146 additions and 0 deletions

46
projecteuler/067/main.cpp Normal file
View File

@@ -0,0 +1,46 @@
#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;
}