当前位置:网站首页>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 代码
边栏推荐
- PPT | 「课件」企业中高层人员安全管理培训(118页)
- What is an abstract class
- 2023版揽胜运动曝光,安全、舒适一个不落
- runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
- "MySQL Advanced Chapter" 6. Principles of index creation and design
- Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!
- 数据库事务
- OSSCore 开源解决方案介绍
- 数据库的约束
- "Data Strategy" Results-Driven Enterprise Data Strategy: Organization and Governance
猜你喜欢
「第二部:容器和微服务架构」(1) 基于容器应用架构设计原则
owl.carousel poster card Slider carousel switch
STM32 encapsulation ESP8266 a key configuration function: implementations of AP mode and the STA mode switch, server and the client to create
越折腾越好用的 3 款开源 APP
【Azure云】服务端点和私有链接有什么区别?观点(1)
ECCV 2022 | 视频理解新框架X-CLIP:仅用微调的成本,达到预训练的全能
Situation丨The intrusion of hackers intensifies, and the shooting range sets up a "defense shield" for network security
Network Security Note 6 - Digital Certificates and Public Key Infrastructure
Redis(三)——配置文件详解、发布和订阅、新数据类型
js猜拳小游戏源码
随机推荐
SQL与NoSQL最终会走向融合吗?
OSSCore 开源解决方案介绍
Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)
what is bsp in rtems
js guessing game source code
金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
"Chief Engineer" Principal (Principal) engineer's way of training
chart.js horizontal column chart plugin
【微服务架构】微服务与SOA架构(2)
谷歌数据中心发生“电力事故”造成 3 人受伤
「时序数据库」使用cassandra进行时间序列数据扫描
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
JWT implements login authentication + Token automatic renewal scheme
Introduction to cross-end development of Taro applet
CodeChef STRMRG String Merging (dp)
Redis (three) - detailed configuration file, publish and subscribe, new data types
The usage and difference between getParameter() and getAttribute()
chart.js水平柱状图插件
STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
「第二部:容器和微服务架构」(1) 基于容器应用架构设计原则