算法真的是,如果不能捅破那道窗户纸,会感觉苦苦地就一直陷在瓶颈里,无法自拔,只有捅破了那道窗户纸才会发现,其实原理那样简单,遗憾的是,很多时候靠自己苦思冥想可能永远都无法找到那层窗户纸!
一道简单的DP(n)、分治算法题(nlogn) 53. Maximum Subarray http://www.cnblogs.com/TenosDoIt/p/3713525.html
96. Unique Binary Search Trees https://leetcode.com/problems/unique-binary-search-trees/
用动态规划,将保存从1~n的所有节点个数对应的二叉排序树的总数,这也是必须的,后面的节点数量需要前面的节点数的解!!
参考博客 http://blog.csdn.net/linhuanmars/article/details/24761459
class Solution { public: int numTrees(int n) { vector<int> dp(n+1,0); dp[0]=dp[1]=1; for(int i=2;i<=n;i++){ for(int j=0;j<i;j++){ dp[i]+=dp[j]*dp[i-j-1]; } } return dp[n]; } };
95. Unique Binary Search Trees II https://leetcode.com/problems/unique-binary-search-trees-ii/
参考博客 http://blog.csdn.net/linhuanmars/article/details/24761437 http://blog.csdn.net/kenden23/article/details/17560461