func max(a, b int) int {
if a > b {
return a
}
return b
}
//拆分的数尽量相等才能保证最大
func integerBreak(n int) int {
dp := make([]int, n+1)
// 初始值,0,1没有意义,为零,2可以拆为1*1=1
dp[2] = 1
for i := 3; i <= n; i++ {
for j := 1; j <= i/2; j++ {
dp[i] = max(max(j*(i-j), j*dp[i-j]), dp[i])
}
}
return dp[n]
}
func numTrees(n int) int {
if n == 0 {
return 1
}
dp := make([]int, n+1)
dp[0] = 1
for i := 1; i <= n; i++ {
for j := 1; j <= i; j++ {
dp[i] += dp[j-1] * dp[i-j]
}
}
return dp[n]
}