树形DP
文章平均质量分 85
memcpy0
希望探索文理结合的自由之路。
展开
-
LeetCode 337. House Robber III【DFS,树型DP】中等
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that “all houses in this plac原创 2020-10-28 15:10:56 · 158 阅读 · 0 评论 -
LeetCode 1617. Count Subtrees With Max Distance Between Cities【数学,二进制枚举,位操作,状压,树型DP,BFS,DFS】困难
There aren1tonedgesof sizen-1, whereuiandviAFor eachdfrom1ton-1dReturnn-1where thedthelementdthat the(ui, vi)题意:给你n个城市,编号为从1到n。给出一个大小为n-1的数组edges,其中表示城市ui和vi之间有一条双向边。题目保证任意城市之间只有唯一的一条路径。即所有城市形成了一棵。一棵是城市集合的一个子集,且子集中任意城市都可以通过子集中的其他城市和边到达。原创 2023-03-13 02:11:41 · 75 阅读 · 0 评论 -
LeetCode C++ 1339. Maximum Product of Splitted Binary Tree【树形DP/DFS】中等
Given a binary tree root. Split the binary tree into two subtrees by removing 1 edge such that the product of the sums of the subtrees are maximized. Since the answer may be too large, return it modulo 10^9 + 7. Example 1: Input:原创 2021-04-02 18:31:03 · 154 阅读 · 0 评论