problem:https://leetcode.com/problems/unique-binary-search-trees/
左子树个数 * 右子树个数
class Solution { public: int numTrees(int n) { vector<int> dp(n + 1); dp[1] = 1; for(int i = 2;i <= n;i++) { dp[i] = dp[i - 1] + dp[i - 1]; for(int j = 1;j <= i - 1; j++) { dp[i] += dp[j] * dp[i - 1 - j]; } } return dp[n]; } };
原文地址:https://www.cnblogs.com/fish1996/p/11329808.html
时间: 2024-10-08 03:54:16