HDU 1520 Anniversary party(DFS或树形DP)
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.
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
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
5
#include<cstdio> #define N 6005 struct p
{
int fm;
int child;
int brother;
int att;
int no;
void init()
{
no=0;
fm=0;
brother=0;
child=0;
}
int Max()
{
return att>no? att:no;
}
}num[N]; void dfs(int x)
{
int child=num[x].child;
while(child)
{
dfs(child);
num[x].att+=num[child].no;
num[x].no+=num[child].Max();
child=num[child].brother;
}
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
num[i].init();
scanf("%d",&num[i].att);
}
int a,b;
while(scanf("%d %d",&a,&b),a||b)
{
num[a].fm=b;
num[a].brother=num[b].child;
num[b].child=a;
}
for(int i=1;i<=n;i++)
{
if(num[i].fm==0)
{
dfs(i);
printf("%d\n",num[i].Max());
break;
}
}
}
return 0;
}
HDU 1520 Anniversary party(DFS或树形DP)的更多相关文章
- HDU 1520.Anniversary party 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- TTTTTTTTTTT hdu 1520 Anniversary party 生日party 树形dp第一题
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1520 Anniversary party || codevs 1380 树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...
- HDU 1520 Anniversary party [树形DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为 ...
- [HDU 1520] Anniversary party
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu_5293_Tree chain problem(DFS序+树形DP+LCA)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5293 被这题打蹦了,看着题解写的,很是爆炸,确实想不到,我用的DFS序+LCA+树形DP,当然也可以写 ...
随机推荐
- Converting Legacy Chrome IPC To Mojo
Converting Legacy Chrome IPC To Mojo Looking for Mojo Documentation? Contents Overview Deciding What ...
- 使用了未经检查或不安全的操作。有关详细信息, 请使用 -Xlint:unchecked 重新编译。
警告信息如下:
- SP687 REPEATS - Repeats(后缀数组)
一个初步的想法是我们枚举重复子串的长度\(L\).然后跑一遍SA.然后我们枚举一个点\(i\),令他的对应点为\(i+L\),然后求出这两个点的LCP和LCS的长度答案就是这个点的答案就是\((len ...
- 解除 linux 账户过期时间
riyimei:~ # chage -E 2019/01/01 li Aging information changed. riyimei:~ # cat /etc/shadow |grep li l ...
- C++根据扩展名获取文件图标、类型
简述 在Windows系统中,根据扩展名来区分文件类型,比如:.txt(文本文件)..exe(可执行程序).*.zip(压缩文件),下面,我们来根据扩展名来获取对应的文件图标.类型. 简述 源码 源码 ...
- cin详解(get()、getline()、clear()、sync())
简述 在C中,输入输出用scanf和printf,在输入数据的同时还需说明数据的类型,如果输入数据较多,那就很麻烦,而C++中也有相似的东西cin和cout,它们来自C++的一个名叫" io ...
- EEPlat PaaS中的多租户数据隔离模式
EEPlat PaaS支持三种租户的数据隔离技术:Sparce Column.tenantId字段隔离.每一个租户独立数据库. 1)Sparce Column,和Salesforce Appforce ...
- [LeetCode]Subsets II生成组合序列
class Solution {//生成全部[不反复]的组合.生成组合仅仅要採用递归,由序列从前往后遍历就可以. 至于去重,依据分析相应的递归树可知.同一个父节点出来的两个分支不能一样(即不能与前一个 ...
- 10.29 工作笔记 ndk编译C++,提示找不到头文件(ndk-build error: string: No such file or directory)
ndk编译C++.提示找不到头文件(ndk-build error: string: No such file or directory) 被这个问题弄得愁眉苦脸啊.心想为啥一个string都找不到呢 ...
- sage开发url替换字符串
/// <summary> /// Url字段值替换,无该字段则加入 /// </summary> /// <param ...