343. 整数拆分
class Solution:
def integerBreak(self, n: int) -> int:
dp = [0] * (n+1)
dp[2] = 1
for i in range(3, n+1):
for j in range(1, i//2+1):
dp[i] = max(dp[i], (i-j)*j, dp[i-j]*j)
return dp[-1]
96.不同的二叉搜索树
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+1):
dp[i] += dp[i-j] * dp[j-1]
return dp[-1]
标签:int,part03,随想录,34,range,343,二叉,dp,96
From: https://www.cnblogs.com/miramira/p/18166308