-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem81.cpp
42 lines (35 loc) · 993 Bytes
/
Problem81.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 <bits/stdc++.h>
using namespace std;
#define upgrade ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pp pair<int, int>
#define size(a) (int)a.size()
#define all(a) a.begin(), a.end()
typedef long long ll;
vector<vector<int>> matrix;
int dp(){
int n = size(matrix), m = size(matrix[0]);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(i == 0 && j == 0) continue;
if(i == 0) matrix[i][j] += matrix[i][j - 1];
else if(j == 0) matrix[i][j] += matrix[i - 1][j];
else matrix[i][j] += min(matrix[i - 1][j], matrix[i][j - 1]);
}
}
return matrix[n - 1][m - 1];
}
int main(){
ifstream in;
string s;
in.open("0081_matrix.txt");
while(getline(in, s)){
stringstream ss(s);
matrix.push_back({});
while(getline(ss, s, ',')){
matrix.back().push_back(stoi(s));
}
}
in.close();
cout << dp();
return 0;
}