POJ 3398 Perfect Service(树型动态规划,最小支配集) Description A network is composed of N computers connected by N − 1 communication links such that any two computers can be communicated via a unique route. Two computers are said to be adjacent if there is a com…
题目链接:http://poj.org/problem?id=3398 这题可以用两种上述讲的两种算法解:http://www.cnblogs.com/whatbeg/p/3776612.html 第一种,贪心算法: 贪心算法直接套一个最小支配集模板就可以了,我不能证明这样是正确的,但是能AC 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #incl…
POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone tow…
POJ 2152 fire / SCU 2977 fire(树型动态规划) Description Country Z has N cities, which are numbered from 1 to N. Cities are connected by highways, and there is exact one path between two different cities. Recently country Z often caught fire, so the governm…
POJ 3342 Party at Hali-Bula / HDU 2412 Party at Hali-Bula / UVAlive 3794 Party at Hali-Bula / UVA 1220 Party at Hali-Bula(树型动态规划) Description Dear Contestant, I'm going to have a party at my villa at Hali-Bula to celebrate my retirement from BCM. I w…
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of emp…
题目求一棵树的最小支配数. 支配集,即把图的点分成两个集合,所有非支配集内的点都和支配集内的某一点相邻. 听说即使是二分图,最小支配集的求解也是还没多项式算法的.而树上求最小支配集树型DP就OK了. 树上的每个结点作为其子树的根可以有三个状态: 不属于支配集且还没被支配 不属于支配集但被其孩子支配 属于支配集 那么就是用dp[u][1\2\3]来作为动归的状态,表示结点u为根子树的且u状态为1.2.3的最小支配数. 123转移该怎么转移就怎么转移..最后的结果就是min(dp[root][2],…
树型动态规划就是在“树”的数据结构上的动态规划,树型动态规划是建立在树上的,所以有二个方向: 1.根—>叶:这种题目基本上碰不到 2.叶->根:根的子节点传递有用的信息给根,完后根得出最优解的过程.这种的题目是树型动态规划的最常见类型. 首先定义 无根树:题目中可以以任意节点为根建树,经过动态规划后即可直接得到最优值. 有根树:必须以某一个节点为根建树才能通过动态规划后得到最优值. 基本上有这样一个步骤: 一.有根树: 1.建树(一般以递归方式实现,有时数据过大以BFS方式实现) 2.在建树中…
CJOJ 1010[NOIP2003]加分二叉树 / Luogu 1040 加分二叉树(树型动态规划) Description 设 一个 n 个节点的二叉树 tree 的中序遍历为( 1,2,3,-,n ),其中数字 1,2,3,-,n 为节点编号.每个节点都有一个分数(均为正整数),记第 j 个节点的分数为 di , tree 及它的每个子树都有一个加分,任一棵子树 subtree (也包含 tree 本身)的加分计算方法如下: subtree 的左子树的加分 × subtree 的右子树的加…
CJOJ 2171 火车站开饭店(树型动态规划) Description 政府邀请了你在火车站开饭店,但不允许同时在两个相连的火车站开.任意两个火车站有且只有一条路径,每个火车站最多有 50 个和它相连接的火车站. 告诉你每个火车站的利润,问你可以获得的最大利润为多少? 例如下图是火车站网络: 最佳投资方案是 1 , 2 , 5 , 6 这 4 个火车站开饭店可以获得的利润为 90. Input 第一行输入整数 N(<=100000), 表示有 N 个火车站,分别用 1,2,--..,N 来编号…