Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 354    Accepted Submission(s): 100 Problem Description ZYB has a tree with N nodes,now he wants you to solve the numbers of nodes distanced no m…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5593 题意: http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=654&pid=1004 题解: 先自底向上跑一遍,求出以u为根的子树中与u距离小于等于k的节点数(不同的距离要分开存,否则无法递推上去,dp[u][i]存距离为i的节点数) 求好之后,再dfs一遍,这次换做自顶向下,目的是求u的兄弟(和兄弟的后代)…
感觉其实就是树分治,一次BC的题,感觉这次题目质量比较高,仅代表蒟蒻的看法 一次DFS获取每个点到子树的距离不大于K的点的个数, 然后一遍BFS获取从每个点父亲不大于K的的个数,层层扩展,还是想说 其实就是树分治.....并没有什么DP /* Problem : 5593 ( ZYB's Tree ) Judge Status : Accepted RunId : 15764784 Language : G++ Author : qianbi08 */ #include<cstdio> #in…
ZYB's Tree Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 400    Accepted Submission(s): 114 Problem Description ZYB has a tree with N nodes,now he wants you to solve the numbers of nodes dis…
ZYB's Tree    Memory Limit: 131072/131072 K (Java/Others) 问题描述 ZYBZYB有一颗NN个节点的树,现在他希望你对于每一个点,求出离每个点距离不超过KK的点的个数. 两个点(x,y)(x,y)在树上的距离定义为两个点树上最短路径经过的边数, 为了节约读入和输出的时间,我们采用如下方式进行读入输出: 读入:读入两个数A,BA,B,令fa_ifa​i​​为节点ii的父亲,fa_1=0fa​1​​=0;fa_i=(A*i+B)\%(i-1)+…
熟练剖分(tree) 树形DP 题目描述 题目传送门 分析 我们设\(f[i][j]\)为以\(i\)为根节点的子树中最坏时间复杂度小于等于\(j\)的概率 设\(g[i][j]\)为当前扫到的以\(i\)为父亲节点的所有儿子最坏时间复杂度小于等于\(j\)的概率之和 因为每遍历到一个新的节点,原来的\(g\)数组中的值就要全部更新,因此我们压掉第一维 下面我们考虑转移 对于当前枚举到的某一个节点,我们用三重循环分别扫一边 第一重循环代表当前哪一个节点充当重儿子,第二重循环枚举所有儿子,第三充循…
题目链接: Magic boy Bi Luo with his excited tree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1037    Accepted Submission(s): 298 Problem Description Bi Luo is a magic boy, he also has a migic…
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…
/** 题目:hdu6035 Colorful Tree 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6035 题意:给定一棵树,每个节点有一个颜色值.定义每条路径的值为经过的节点的不同颜色数.求所有路径的值和. 思路:看题解后,才想出来的.树形dp. 求所有路径的值和 = 路径条数*总颜色数(n*(n-1)*colors/2)-sigma(每种颜色没有经过的路径条数) 主要是求每种颜色没有经过的路径条数. 画一棵树,我直接用颜色值表示节点编号. 2…