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

    not difficult, it is easy

    first you should decide the root num, then the litter num is left of it, the bigger nums are right of it;
    we can get that
    f(n) = f(n-1) + f(1) * f(n-2) + f(2) * f(n-3) +... + f(n-2) * f(1) + f(n-1)
    we can makesure that f(0) = 1
    and then
    f(n) = ∑f(k) * f(n-1-k)
    so we use db solution

    class Solution {
    public:
        vector<int> kinds_num(int n){
            vector<int> result;
            result.push_back(1);
            for (int i=1;i<=n;i++){
                int tmp = 0;
                for (int j=0;j<=i-1;j++){
                    tmp += result[j] * result[i-1-j];
                }
                result.push_back(tmp);
            }
            return result;
        }
        int numTrees(int n) {
            vector<int> result;
            result = kinds_num(n);
            return result[n];
        }
    };
  • 相关阅读:
    Tensorflow io demo (待)
    tf.Dataset
    tf.estimator
    并发队列
    Callable的Future模式
    hadoop之HDFS介绍
    线程池
    并发工具类
    并发编程
    初学hadoop之hadoop集群搭建
  • 原文地址:https://www.cnblogs.com/mangmangbiluo/p/11033209.html
Copyright © 2011-2022 走看看