zoukankan      html  css  js  c++  java
  • 【Leetcode】96. Unique Binary Search Trees

    This is a BST(binary search tree) numbers counting problem but solved in dynamic programing.

    https://discuss.leetcode.com/category/104/unique-binary-search-trees

    This solution really gives me a shock. Before solving u need do some mathematical deduce in papers and get the dp function, which fantistically! 

    class Solution {
    public:
        int numTrees(int n) {
            int G[100];
            for(int i = 0; i <= n; i ++)
                G[i] = 0;
            G[0] = G[1] = 1;
            for(int i = 2; i <= n; i ++){
                for(int j = 1; j <= i; j ++)
                    G[i] += G[j - 1] * G[i - j];
            }
            return G[n];
        }
    };

     

  • 相关阅读:
    Ubuntu下 实现Linux与Windows的互相复制与粘贴
    bzoj2426
    bzoj1835
    bzoj1197
    bzoj1049
    bzoj2893
    bzoj1820
    bzoj1819
    bzoj1455
    bzoj3689
  • 原文地址:https://www.cnblogs.com/luntai/p/5648361.html
Copyright © 2011-2022 走看看