随笔分类 - 动态规划 - 树形dp
摘要:leedcode : https://leetcode-cn.com/problems/sum-of-distances-in-tree/ 思路 : 一遍 dfs 可以求到以任意一个点为根,所有点所含孩子的个数,cnt数组记录 考虑每一条边的贡献时,即此边左右节点数相乘 第2遍 dfs, 以其他点为
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/contest/272/B来源:牛客网 题目描述 给定一棵n个点的树,每个点有权值。定义表示 到 的最短路径上,所有点的点权异或和。 对于,求所有的异或和。 输入描述: 第一行一个整数n。 接下来n-1行,每行2个整数u,v,表示u,v之
阅读全文
摘要:链接:https://www.nowcoder.com/acm/contest/215/C来源:牛客网 题目描述 “你,你认错人了。我真的,真的不是食人魔。”--蓝魔法师 给出一棵树,求有多少种删边方案,使得删后的图每个连通块大小小于等于k,两种方案不同当且仅当存在一条边在一个方案中被删除,而在另一
阅读全文
摘要:The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed to trade it. The trading price of the Power Cube
阅读全文
摘要:Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), was the founder of the Mongol Empire and the grea
阅读全文
摘要:Alice and Bob are going on a trip. Alice is a lazy girl who wants to minimize the total travelling distance, while Bob as an active boy wants to maxim
阅读全文
摘要:A school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new co
阅读全文
摘要:A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, we need 1 unit of cost respectively. The nodes are labeled from 1 to N.
阅读全文
摘要:随着杭州西湖的知名度的进一步提升,园林规划专家湫湫希望设计出一条新的经典观光线路,根据老板马小腾的指示,新的风景线最好能建成环形,如果没有条件建成环形,那就建的越长越好。 现在已经勘探确定了n个位置可以用来建设,在它们之间也勘探确定了m条可以设计的路线以及他们的长度。请问是否能够建成环形的风景线?如
阅读全文
摘要:poj 2342 Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9480 Accepted: 5454 Description There is going to be a party to
阅读全文