Anniversary party

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

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

思路:两个状态;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
int a[N];
int du[N];
vector<int>v[N];
int dp[N][];
void dfs(int x,int step)
{
for(int i=;i<v[x].size();i++)
{
dfs(v[x][i],step+);
dp[x][]+=max(dp[v[x][i]][],dp[v[x][i]][]);
dp[x][]+=dp[v[x][i]][];
}
}
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
memset(dp,,sizeof(dp));
memset(du,,sizeof(du));
for(i=;i<=x;i++)
v[i].clear();
for(i=;i<=x;i++)
scanf("%d",&a[i]),dp[i][]=a[i];
while()
{
scanf("%d%d",&y,&z);
if(y==&&z==)
break;
du[y]++;
v[z].push_back(y);
}
for(i=;i<=x;i++)
if(du[i]==)
{
dfs(i,);
break;
}
printf("%d\n",max(dp[i][],dp[i][]));
}
return ;
}

hdu 1520 Anniversary party || codevs 1380 树形dp的更多相关文章

  1. HDU 1520.Anniversary party 基础的树形dp

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

  2. TTTTTTTTTTT hdu 1520 Anniversary party 生日party 树形dp第一题

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

  3. 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 ...

  4. hdu 1520 Anniversary party(第一道树形dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...

  5. POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题

    一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...

  6. HDU 1520 Anniversary party [树形DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为 ...

  7. HDU 1520 Anniversary party(DFS或树形DP)

    Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...

  8. [HDU 1520] Anniversary party

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

  9. HDU 3586 Information Disturbing(二分+树形dp)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3586 题意: 给定一个带权无向树,要切断所有叶子节点和1号节点(总根)的联系,每次切断边的费用不能超 ...

随机推荐

  1. java中byte和blob互转

    1. btye[]转blob byte[] bs = ... Blob blob = conn.createBlob(); blob.setBytes(1, bs); ps.setBlob(2, bl ...

  2. 在JavaScript中实现yield,实用简洁实现方式。

    原题还是老赵的: http://blog.zhaojie.me/2010/06/code-for-fun-iterator-generator-yield-in-javascript.html 原以为 ...

  3. CodeForces 321A

    A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. D3D Deferred Shading

    在3D图形计算中,deferred shading是一个基于屏幕空间的着色技术.之所以被称为deferred shading,是因为我们将场景的光照计算与渲染"deferred"到 ...

  5. 让Word2007、word2003中的GIF图片动起来

    在PPT中插入会动的GIF图片,播放是生动有趣:可是GIF图片插入Word2007文档后却变成了静态画面,表现效果大打折扣.让我们装一个小控件,让图片动起来! 第一步:下载AniGIF.ocx控件,解 ...

  6. POJ 1507

    #include<iostream> #include<stdio.h> using namespace std; #include<iomanip> double ...

  7. DB2常用函数:字符串函数

    VALUE函数 语法:VALUE(EXPRESSION1,EXPRESSION2) VALUE函数是用返回一个非空的值,当其第一个参数非空,直接返回该参数的值,如果第一个参数为空,则返回第一个参数的值 ...

  8. OleDbType.Decimal在插入DB2后会默认赋值0.00,改为OleDbType.Double则正常

    private void InsertShopClaimsTarget(ContinueTargetData.RT_SHOPCLAIMSTARGETRow aRow) { StringBuilder ...

  9. 传说中的WCF(8):玩转消息协定

    Message翻译成中文,相信各位不陌生,是啊,就是消息,在WCF中也有消息这玩意儿,不知道你怎么去理解它.反正俺的理解,就像我们互发短信一个道理,通讯的双方就是服务器与客户端,说白了吧,就是二者之间 ...

  10. tvm install

    一.系统需求:1.可以访问互联网2.关闭防火墙和selinux 二.安装步骤(进入软件包所在目录):1.rpm -ivh daemontools-0.76-1.el6.x86_64.rpm2.yum ...