hdu 1520
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6401 Accepted Submission(s): 2862
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.
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
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%lld", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define MAXN 6005
int w[MAXN];
bool f[MAXN] = {false};
vector<int> v[MAXN];
int d[MAXN][];
bool vis[MAXN] = {false};
void dp(int root)
{
if(vis[root]) return ;
vis[root] = true;
int siz = v[root].size();
repu(i, , siz) dp(v[root][i]); repu(i, , siz)
{
d[root][] += max(d[v[root][i]][], d[v[root][i]][]);
d[root][] += d[v[root][i]][];
}
return ;
}
int main()
{
int n;
while(~sfi(n))
{
_cle(vis, false);
_cle(f, false);
repu(i, , n + )
{
sfi(w[i]);
v[i].clear();
d[i][] = ;
d[i][] = w[i];
}
int x, y;
while(sfi(x), sfi(y), x + y)
{
v[y].push_back(x);
f[x] = true;
}
int root;
repu(i, , n + ) if(!f[i])
{
root = i;
break;
}
dp(root);
pfi(max(d[root][], d[root][]));
//repu(i, 1, n + 1) printf("%d %d\n", d[i][0], d[i][1]);
} return ;
}
hdu 1520的更多相关文章
- HDU 1520 树形dp裸题
1.HDU 1520 Anniversary party 2.总结:第一道树形dp,有点纠结 题意:公司聚会,员工与直接上司不能同时来,求最大权值和 #include<iostream> ...
- 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 树形DP入门
HDU 1520 [题目链接]HDU 1520 [题目类型]树形DP &题意: 某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知 ...
- HDU 1520:Anniversary party(树形DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Problem Description There i ...
- 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 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1520(简单树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u] ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- hdu 1520 树形DP基础
http://acm.hdu.edu.cn/showproblem.php?pid=1520 父节点和子节点不能同时选. http://blog.csdn.net/woshi250hua/articl ...
随机推荐
- [数据结构与算法]队列Queue 的多种实现
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 如何在本机上将localhost改为www.dev.com
windows上安装好服务器后,打开本地目录 C:\Windows\System32\drivers\etc\ ,会看到有个hosts文件,打开后里面的代码为: # Copyright (c) - M ...
- Mysql 命令行工具
1.Mysql命令行工具分为两类:服务端命令行工具和客户端命令行工具. 2.服务端工具 mysql_install_db:建库工具 mysqld_safe:Mysql服务的启动工具,mysqld_sa ...
- Java面向对象深度
局部内部类 package ch6; /** * Created by Jiqing on 2016/11/21. */ public class LocalInnerClass { // 局部内部类 ...
- Android ViewFlipper的使用分析
[ViewFlipper]——基础 1.ViewPager 和ViewFliping的区别: 最显著的区别就是ViewPager在滑动的时候内部的View默认就能够跟随手指滑动,而 ViewFlipi ...
- uva 11800 Determine the Shape
vjudge上题目链接:Determine the Shape 第二道独自 A 出的计算几何水题,题意就是给你四个点,让你判断它是哪种四边形:正方形.矩形.菱形.平行四边形.梯形 or 普通四边形. ...
- WebKit渲染基础(转载 学习中。。。)
概述 WebKit是一个渲染引擎,而不是一个浏览器,它专注于网页内容展示,其中渲染是其中核心的部分之一.本章着重于对渲染部分的基础进行一定程度的了解和认识,主要理解基于DOM树来介绍Render树和R ...
- 网络性能测试工具iperf详细使用图文教程【转载】
原文:http://blog.163.com/hlz_2599/blog/static/142378474201341341339314/ 参考:http://man.linuxde.net/iper ...
- 慢慢聊Linux AIO
一.What:异步IO是什么? 1. 一句话总结 允许进程发起很多I/O操作,而不用阻塞或等待任何操作完成 2. 详细说说 一般来说,服务器端的I/O主要有两种情况:一是来自网络的I/O:二是对文件 ...
- MyBatis学习笔记(二) 关联关系
首先给大家推荐几个网页: http://blog.csdn.net/isea533/article/category/2092001 没事看看 - MyBatis工具:www.mybatis.tk h ...