https://www.hackerrank.com/contests/hourrank-21/challenges/tree-isomorphism 题目大意: 给出一棵树, 求有多少本质不同的子树. N <= 19 下面给出我综合了网上一些做法后设计的hash函数(我不会证明碰撞概率) 判断两棵有根树是否相同: 将子树的Hash值从小到大排序, Hash(x) = A * p xor Hash(son_1) mod q * p xor Hash(son_2) mod q ....…
题目链接 大意 给出一颗树,按下列方式生成一个括号序列. function dfs(int cur, int parent): print('(') for all nxt that cur is adjacent to: dfs(nxt, cur) print(')') 其中可以从任一点出发,且对儿子的遍历顺序是随机的. 求本质不同的括号序列个数. 思路 前置板块:树Hash 如何判断两颗有根树是否本质一样? 我们先随机生成一个\(T\)数组(随机数被卡概率小?) 令\(Siz[u]\)表示\…
描述 A binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as "left" and "right". A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T. Two binar…