https://leetcode-cn.com/problems/unique-binary-search-trees/
一棵树n个节点,根节点一个,剩下n-1个,左右子树分, 数量从0到n-1,然后乘起来,因为是步骤。
class Solution {
public:
int numTrees(int n) {
int dp[n+1];
memset(dp,0,sizeof(dp));
dp[0]=1;
dp[1]=1;
for(int i=2;i<=n;i++){
for(int x=0;x<=i-1;x++){
int y=i-1-x;
dp[i]+=(dp[x]*dp[y]);
}
}
return dp[n];
}
};