当前位置:网站首页>HDU 1520 Anniversary party (树型dp)
HDU 1520 Anniversary party (树型dp)
2022-08-10 10:33:00 【51CTO】
Problem 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 employees. It means that the supervisor relation forms a tree rooted at the rector V. E. Tretyakov. In order to make the party funny for every one, the rector does not want both an employee and his or her immediate supervisor to be present. The personnel office has evaluated conviviality of each employee, so everyone has some number (rating) attached to him or her. Your task is to make a list of guests with the maximal possible sum of guests’ conviviality ratings.
Input
Employees are numbered from 1 to N. A first line of input contains a number N. 1 <= N <= 6 000. Each of the subsequent N lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from -128 to 127. After that go T lines that describe a supervisor relation tree. Each line of the tree specification has the form:
L K
It means that the K-th employee is an immediate supervisor of the L-th employee. Input is ended with the line
0 0
Output
Output should contain the maximal sum of guests’ ratings.
Sample Input
Sample Output
题意
输入 n 个节点以及这些节点的活跃值,然后输入 a b ,代表 b 是 a 的上司,有直接关系的上司和下属不能同时参加Patty,求Patty的最大活跃值。
思路
可以先按照给出的关系建树。
每一个节点有两种状态,参加与不参加, 0 代表不参加, 1 代表参加。
我们定义 dp[i][0] 为以 i 为根的子树且 i 不参加所能得到的最大活跃值, dp[i][1] 为 i 参加所能得到的最大活跃值。
状态转移方程:
dp[i][0]+=max(dp[j][1],dp[j][0]);
dp[i][1]+=dp[j][0];
其中 j 是 i 的所有下属。
AC 代码
边栏推荐
猜你喜欢

兼容移动和PC的loading加载和toast消息插件

用proteus直接仿真stm32-可以完全丢弃编程器

Situation丨The intrusion of hackers intensifies, and the shooting range sets up a "defense shield" for network security

Automated Testing and Selenium

ESP8266 教程2 — 烧录AT固件

网络安全笔记6——数字证书与公钥基础设施

第2章-矩阵及其运算-矩阵运算(2)

态势丨黑客侵扰加剧,靶场为网络安全架设“防御盾”

TCP/IP笔记

SQL中的字符串截取函数
随机推荐
Dialogue with Chen Ciliang: Nezha wants to popularize high-end products
PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
JWT 实现登录认证 + Token 自动续期方案
leetcode:334. 递增的三元子序列
"Scalability" extensibility best practices: lessons from eBay
Flutter实战-请求封装(五)之Isolate线程改造
用proteus直接仿真stm32-可以完全丢弃编程器
Array of shell scripts
mysql5.7 installation and deployment - yum installation
[C language] Floating point number rounding
Gartner reiterates the important value of 'data weaving'
database constraints
[Concept of Theory of Knowledge] "Progress in the Theory of Reason" University of Leuven 2022 latest 220-page doctoral dissertation
SQL中的字符串截取函数
ZZULIOJ 1116 删除元素【删】
Mount [shell][mount -o loop]
ECCV 2022 | 视频理解新框架X-CLIP:仅用微调的成本,达到预训练的全能
FastReport.Net 2022.2.17 Crack
chart.js horizontal column chart plugin
「第二部:容器和微服务架构」(1) 基于容器应用架构设计原则