Merge branch 'master' of ssh://git.pzwietering.nl:55555/flip/contests

This commit is contained in:
2022-05-29 16:23:38 +02:00
22 changed files with 549 additions and 1 deletions

View File

@@ -7,8 +7,51 @@ int main(){
cout << "Hello this is Patrick" << endl;
auto start = chrono::high_resolution_clock::now();
// Insert code here
// I imagine we have to do something with memoization, building up the cheapest path from
// the bottom right corner up to the top left corner
// First read the matrix file
vector<vector<long long>> matrix(80);
ifstream matrixFile("matrix.txt");
for(int i = 0; i < 80; ++i){
for(int j = 0; j < 80; ++j){
int n;
matrixFile >> n;
matrix[i].push_back(n);
if(j != 79){
char c;
matrixFile >> c;
}
}
}
vector<vector<long long>> dp(80);
for(int i = 0; i < 80; ++i){
for(int j = 0; j < 80; ++j){
dp[i].push_back(-1);
}
}
dp[79][79] = matrix[79][79];
for(int i = 78; i >= 0; --i){
dp[i][79] = matrix[i][79] + dp[i+1][79];
}
for(int j = 78; j >= 0; --j){
dp[79][j] = matrix[79][j] + dp[79][j+1];
}
for(int i = 78; i >= 0; --i){
for(int j = 78; j >= 0; --j){
dp[i][j] = matrix[i][j] + min(dp[i+1][j], dp[i][j+1]);
}
}
cout << dp[0][0] << endl;
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
cout << (float)duration.count()/1000 << endl;
return 0;