-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3332.cpp
More file actions
29 lines (29 loc) · 1.09 KB
/
3332.cpp
File metadata and controls
29 lines (29 loc) · 1.09 KB
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
class Solution {
public:
int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {
vector<int> maxScores(n, 0);
vector<int> maxScoresTemp(n, 0);
for (int i = 0; i < k; ++i) {
// stay
for (int current = 0; current < n; ++current) {
maxScoresTemp[current] = max(maxScoresTemp[current], maxScores[current] + stayScore[i][current]);
}
// move
for (int current = 0; current < n; ++current) {
for (int next = 0; next < n; ++next) {
if (current == next) continue;
maxScoresTemp[next] = max(maxScoresTemp[next], maxScores[current] + travelScore[current][next]);
}
}
// update
for (int current = 0; current < n; ++current) {
maxScores[current] = maxScoresTemp[current];
}
}
int res = 0;
for (int current = 0; current < n; ++current) {
res = max(res, maxScores[current]);
}
return res;
}
};