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…
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…
题目传送门 /* 题意:上司在,员工不在,反之不一定.每一个人有一个权值,问权值和最大多少. 树形DP:把上司和员工的关系看成根节点和子节点的关系,两者有状态转移方程: dp[rt][0] += max (dp[son][1], dp[son][0]); //上司不去 dp[rt][1] += dp[son][0]; //上司去,员工都不去 */ #include <cstdio> #include <cstring> #include <algorithm> #inc…
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 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…
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…
题目链接:https://cn.vjudge.net/contest/277955#problem/A 题目大意:略 具体思路:刚开始接触树形dp,说一下我对这个题的初步理解吧,首先,我们从根节点开始,往下dfs,dp[i][0]代表我当前的i点不要去舞会,那么对于他的孩子节点,我们是肯定不能去舞会的,所以dp[i][0]=dp[i][0]+max(dp[son][0],dp[son][1])(注意一个上司可能有多个下属,所以需要累加),这个的具体意思是如果当前的父亲节点不去的话,我们可以选择他…
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1039 Dynamic Programming. 建立树形结构,每个employee有两个选择,去或者不去.supervisor的选择影响着sub-tree的选择.代码如下: #include <iostream> #include <math.h> #include <stdio.h> #include <cstdio> #include <…
今天开始做老师给的专辑,打开DP专辑 A题 Rebuilding Roads 直接不会了,发现是树形DP,百度了下了该题,看了老半天看不懂,想死的冲动都有了~~~~ 最后百度了下,树形DP入门,找到了 poj 2342 Anniversary party   先入门一下~ 题意: 某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知每个人的活跃指数和上司关系(当然不可能存在环),求邀请哪些人(多少人)来能使得晚会的总活跃指数最大. 思路…
题目链接:  POJ - 2342 题目大意:给你n个人,然后每个人的重要性,以及两个人之间的附属关系,当上属选择的时候,他的下属不能选择,只要是两个人不互相冲突即可.然后问你以最高领导为起始点的关系网的重要性最大. 具体思路:简单树形DP, dp[i][0]表示当前i点不选择,那么dp[i][0] =  sum( max(dp[to][1] ,dp[to][0] ) )(to为i的子节点). dp[i][1]表示当前i点选择, 那么dp[i][1] = dp[i][1] + sum(dp[to…