-
Notifications
You must be signed in to change notification settings - Fork 0
/
1235.jobScheduling.h
33 lines (29 loc) · 1.05 KB
/
1235.jobScheduling.h
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
#pragma once
int max_profit = 0;
int tmp_max = 0;
void DFSJOB(vector<int>& startTime, vector<int>& endTime, vector<int>& profit, int start) {
for (int i = start; i < startTime.size(); i++) {
int end = endTime[start];
for (int j = i + 1; j < startTime.size(); j++) {
if (startTime[j] >= end) {
DFSJOB(startTime, endTime, profit, j);
}
}
max_profit = max(tmp_max, max_profit);
tmp_max += profit[start];
for (int j = i + 1; j < startTime.size(); j++) {
if (startTime[j] >= end) {
DFSJOB(startTime, endTime, profit, j);
}
}
max_profit = max(tmp_max, max_profit);
tmp_max -= profit[start];
}
}
int jobScheduling(vector<int>& startTime, vector<int>& endTime, vector<int>& profit) {
for (size_t i = 0; i < startTime.size(); i++) {
DFSJOB(startTime, endTime, profit, i);
tmp_max = 0;
}
return max_profit;
}