You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
lavos/cap4/ex28.go

17 lines
282 B

package cap4
// Ex28 最长不下降子序列
func Ex28(nums []int) int {
dp := make([]int, len(nums))
for i := 0; i < len(nums); i++ {
dp[i] = 1
for j := 0; j < len(nums); j++ {
if nums[i] > nums[j] {
dp[i] = max(dp[i], dp[j]+1)
}
}
}
return dp[len(dp)-1]
}