-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLC0209.py
32 lines (27 loc) · 1.09 KB
/
LC0209.py
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
class Solution:
def minDifficulty(self, jobDifficulty, days):
length = len(jobDifficulty)
if days > length:
return -1
min_difficulties = [[float('inf')] * length for _ in range(days)]
max_diff = 0
i = 0
while i <= length - days:
max_diff = max(max_diff, jobDifficulty[i])
min_difficulties[0][i] = max_diff
i += 1
current_day = 1
while current_day < days:
to = current_day
while to <= length - days + current_day:
current_job_difficulty = jobDifficulty[to]
result = float('inf')
j = to - 1
while j >= current_day - 1:
result = min(result, min_difficulties[current_day - 1][j] + current_job_difficulty)
current_job_difficulty = max(current_job_difficulty, jobDifficulty[j])
j -= 1
min_difficulties[current_day][to] = result
to += 1
current_day += 1
return min_difficulties[days - 1][length - 1]