博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1520(树形DP)
阅读量:6592 次
发布时间:2019-06-24

本文共 1863 字,大约阅读时间需要 6 分钟。

Anniversary party

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 9137    Accepted Submission(s): 3917

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
7 1 1 1 1 1 1 1 1 3 2 3 6 4 7 4 4 5 3 5 0 0
 

 

Sample Output
5
树形DP和线性DP差不多.   dfs一下。
#include 
#include
#include
#include
#include
using namespace std;int n;int happy[6005];vector
son[6005];int dp[6005][3];int vis[6005];void dfs(int now){ dp[now][1] = happy[now]; dp[now][0] = 0; for(int i=0;i

 

转载于:https://www.cnblogs.com/littlepear/p/5747829.html

你可能感兴趣的文章
求js数组中最小值
查看>>
学习笔记之机器学习(Machine Learning)
查看>>
正确率、召回率和 F 值
查看>>
UVA10018 Reverse and Add
查看>>
nodejs实现简易MVC
查看>>
【转载】CocoaPods安装和使用教程
查看>>
Kettle提高输入输出数据总结
查看>>
7.16学习进度
查看>>
python之字符编码(三)
查看>>
前三次作业总结——分析与反思
查看>>
【BZOJ2117】 [2010国家集训队]Crash的旅游计划
查看>>
C++内存释放问题~
查看>>
安装ESXI 5.5卡在LSI_MR3.V00解决方案
查看>>
java反射
查看>>
自定义页面,组件加载
查看>>
UIimageView的contentmodel现实模式一看就懂
查看>>
C语言基础学习5:字符串与指针
查看>>
开源中国+soucetree
查看>>
jsp的九大内置对象和四大作用域
查看>>
新iPad未到 老iPad价格反弹
查看>>