树
文章平均质量分 75
nka_kun
ACMer
展开
-
二叉树前序、中序、后序遍历相互求法
什么叫前中后序遍历:前序遍历: 1.访问根节点 2.前序遍历左子树 3.前序遍历右子树 中序遍历: 1.中序遍历左子树 2.访问根节点 3.中序遍历右子树 后序遍历: 1.后序遍历左子树 2.后序遍历右子树 3.访问根节点之前看到了从另一个网站上写的例子,举的挺好的,直接拿来举出来吧。原创 2017-07-25 15:37:17 · 609 阅读 · 0 评论 -
CodeForces960DFull Binary Tree Queries(二叉树的操作)
Full Binary Tree QueriesYou have a full binary tree having infinite levels.Each node has an initial value. If a node has value x, then its left child has value 2·x and its right child has value 2·x + ...原创 2018-04-14 22:30:29 · 596 阅读 · 0 评论 -
ZOJ-3602Count the Trees(hash处理+map)
Count the TreesTime Limit: 2 Seconds Memory Limit: 65536 KBA binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as "left" and "right". A su...原创 2018-04-23 17:42:08 · 190 阅读 · 0 评论 -
CodeForces - 1060E Sergey and Subway(树上任意两点之间的距离和)
Sergey and SubwaySergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and eve...原创 2018-10-05 21:26:22 · 977 阅读 · 0 评论 -
51nod 1405 树的距离之和
1405 树的距离之和基准时间限制:1 秒 空间限制:131072 KB给定一棵无根树,假设它有n个节点,节点编号从1到n, 求任意两点之间的距离(最短路径)之和。Input第一行包含一个正整数n (n <= 100000),表示节点个数。后面(n - 1)行,每行两个整数表示树的边。Output每行一个整数,第i(i = 1,2,…n)行表示所有节点到第i个点的距离之和。I...原创 2018-10-05 21:30:25 · 251 阅读 · 0 评论 -
POJ - 1947 Rebuilding Roads (树形DP)
题目链接:http://poj.org/problem?id=1947题意:给出一棵n个节点的树,问剖出一颗含有p个节点的子树最少需要砍掉多少条边.(n<= 150)思路:树形DP,f[i][j]表示在以i为根的树上剖出j个节点并且包含i节点的子树最少需要砍掉的边数。初始f[i][1]等于他的孩子树. f[i][j] = min(f[k][l]+f[i][j-l]-1),减1...原创 2018-11-30 13:00:42 · 217 阅读 · 1 评论