-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path568.cpp
More file actions
23 lines (21 loc) · 758 Bytes
/
568.cpp
File metadata and controls
23 lines (21 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int maxVacationDays(vector<vector<int>>& flights, vector<vector<int>>& days) {
int cityNum = flights.size();
int weekNum = days[0].size();
vector<int> dp(cityNum, INT_MIN);
dp[0] = 0;
for (int wk = 0; wk < weekNum; ++wk) {
vector<int> dpTemp(cityNum, INT_MIN);
for (int to = 0; to < cityNum; ++to) {
for (int from = 0; from < cityNum; ++from) {
if (to == from || flights[from][to]) {
dpTemp[to] = max(dpTemp[to], dp[from] + days[to][wk]);
}
}
}
dp = dpTemp;
}
return *max_element(dp.begin(), dp.end());
}
};