** 今天的两道题都非常难,二刷的时候要重点整理思路**
class Solution:
def integerBreak(self, n: int) -> int:
dp = [0 for _ in range(n+1)]
dp[2] = 1
for i in range(3, n+1):
for j in range(1, i):
dp[i] = max(dp[i], j*(i-j), j*dp[i-j])
return dp[n]
class Solution:
def numTrees(self, n: int) -> int:
dp = [0] * (n+1)
dp[0] = 1
for i in range(1, n+1):
for j in range(i):
dp[i] += dp[j] * dp[i-1-j]
print(dp)
return dp[n]