Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, the ...
分类:
其他好文 时间:
2020-01-07 13:18:06
阅读次数:
58
11.5最小生成树(Minimum Spanning Trees) 对加权图求使得权值和最小的生成树,即为最小生成树,基于以点为基准和以边为基准,有两种求最小生成树的方法:Prim算法和Kruskal "最小生成树的具体算法实现" ...
分类:
其他好文 时间:
2020-01-05 00:45:27
阅读次数:
100
11.2树的一些运用(Applications of Trees) 二叉搜索树(Binary Search Trees) 二叉搜索树中,规定数据存储在节点中,且规定右孩子的key大于父节点,左孩子的key小于父节点(如果存在的话) 一般情况下,二叉搜索树查找,插入(必插到叶子节点上)和删除的时间复杂 ...
分类:
移动开发 时间:
2020-01-05 00:28:02
阅读次数:
123
11.1树(TREES) 树的特点: 1. 树是一个无向无环图,任意两个节点间都有唯一的一个简单路径 2. 一系列树组成森林(forest) 3. 树或森林的叶子节点指悬挂点(pendant)或孤立顶点(isolated vertex) 4. 内部顶点(internal node)的度≥2 有根树( ...
分类:
其他好文 时间:
2020-01-04 22:20:59
阅读次数:
99
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a ...
分类:
其他好文 时间:
2020-01-04 14:40:32
阅读次数:
74
原题 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 原题url:https://leetcode cn.com/problems/unique binary search trees/ 解题 这道题看到的第一眼,就和之前的格雷编码一样,又想用动态规划,每次都是遍历 ...
分类:
其他好文 时间:
2020-01-01 11:51:39
阅读次数:
75
"Link" Solution 一棵$n$个点的树应满足度数和$\sum a_i=2n 2$。而且只要度数和满足条件就一定能根据构造出一棵这样的树。 转化成求有多少种方案满足$\sum\limits_{i=1}^ma_i=2m 2$,$m$任意。移下项就是:$\sum\limits_{i=1}^m( ...
分类:
其他好文 时间:
2019-12-30 09:50:18
阅读次数:
96
题目描述:给予两个二叉树 t1 , t2 ,合并他们。 Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overl ...
分类:
其他好文 时间:
2019-12-30 09:14:14
阅读次数:
78
"?? ?? ??" 题意:现在已知圣诞树在x位置,求人的位置,使每个人到达距离他最近的树的距离之和最小 安排人肯定从树旁边开始安排,树的距离为1的位置安排满之后继续安排下一层,因为线无线长,也没什么限制,就直接bfs ...
分类:
其他好文 时间:
2019-12-29 11:20:14
阅读次数:
67
"题目" 插头dp,由于我们不需要判断曼哈段回路是否提前闭合,所以并不要括号序列,直接二进制状压一条轮廓线即可, $1$表示这个位置有插头,$0$表示没有 在考虑到$(i,j)$我们考虑一下$(i,j 1)$是否有向右的插头,$(i 1,j)$是否有向下的插头 之后转移可以大力讨论一波 右没有下没有 ...
分类:
其他好文 时间:
2019-12-27 13:32:29
阅读次数:
53