forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1335.go
More file actions
37 lines (33 loc) · 704 Bytes
/
Copy path1335.go
File metadata and controls
37 lines (33 loc) · 704 Bytes
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
func minDifficulty(jobDifficulty []int, d int) int {
n := len(jobDifficulty)
if n < d {
return -1
}
dp := make([]int, n + 1)
for i := n - 1; i >= 0; i-- {
dp[i] = max(dp[i + 1], jobDifficulty[i])
}
for t := 1; t <= d; t++ {
for i := 0; i <= n - t; i++ {
m := 0
dp[i] = 10010
for j := i; j <= n - t; j++ {
m = max(m, jobDifficulty[j])
dp[i] = min(dp[i], m + dp[j + 1])
}
}
}
return dp[0]
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}