题意: 给你一棵树,n个节点,每条边有长度. 然后有q组询问(u,k),每次问你:从节点u出发,走到某个节点的距离mod k的最大值. 题解: 对于无根树上的dp,一般都是先转成以1为根的有根树,然后分别从上到下和从下到上两遍dp. 另一个技巧是:处理重复走边的情况时,可以让dp值表示达到某种状态的方案数. 表示状态: dp[i][j][k] = max dis 表示从i节点出发,走的距离mod k = j时的方案数 找出答案: 对于每次询问(u,k),答案为:满足dp[u][d][k]>0的最…
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3    法I:后序遍历.同Unique Binary Search Trees II,只是现在…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 557 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 567 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
Description One traveler travels among cities. He has to pay for this while he can get some incomes. Now there are n cities, and the traveler has m days for traveling. Everyday he may go to another city or stay there and pay some money. When he come…
Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. mnson[ i ][ 0 ] 和 mnson[ i ][ 1 ]分别表示 i 的儿子的dp值的最大和第二大的值, 那么dp[ i ] = max(mnson[ i ][ 0 ], mnson[ i ][ 1 ] + 1) 根据树链剖分的原理我们知道dp的最大值不超过log(n), 那么每次加入一个新的…
Tree chain problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1798    Accepted Submission(s): 585 Problem Description Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.The…
Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1574    Accepted Submission(s): 511 Problem Description In the Data structure class of HEU, the teacher asks one problem: How to find the lon…
题目链接 BZOJ 洛谷 先求最短路树.考虑每一条非树边(u,v,len),设w=LCA(u,v),这条边会对w->v上的点x(x!=w)有dis[u]+dis[v]-dis[x]+len的距离. 每条边用dis[u]+div[v]+len更新链.树剖就做完了. 因为每个点只需取最小值,所以把边按dis[u]+div[v]+len排序后并查集更新链也行. 复杂度\(O(n\alpha(n)+mlogm)\). 树DP失败,好像没法处理子树内的ndis互相更新..唉. //12680kb 556m…
Partial Tree http://acm.hdu.edu.cn/showproblem.php?pid=5534 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description In mathematics, and more specifically in graph theory, a tree…