【Poj】 p2342 Anniversary party(树形DP第一道)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5523 | Accepted: 3169 |
Description
Input
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
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
Source
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int f[][],used[],father[];
void treee(int num)
{
int i;
used[num]=;
for (i=;i<=n;i++)
{
if (!used[i] && father[i]==num)
{
treee(i);
f[num][]+=f[i][];
f[num][]+=max(f[i][],f[i][]);
}
}
}
int main()
{
int root,a,b,bb;
int i;
while (~scanf("%d",&n))
{
memset(father,,sizeof(father));
memset(used,,sizeof(used));
memset(f,,sizeof(f));
for (i=;i<=n;i++)
scanf("%d",&f[i][]);
root=;
bb=;
while (scanf("%d%d",&a,&b),a||b)
{
father[a]=b;
if (a==root || bb==)
{
root=b;
}
}
while (father[root])
root=father[root];
treee(root);
printf("%d",max(f[root][],f[root][]));
}
return ;
}
【Poj】 p2342 Anniversary party(树形DP第一道)的更多相关文章
- poj 2324 Anniversary party(树形DP)
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...
- POJ 2342 - Anniversary party - [树形DP]
题目链接:http://poj.org/problem?id=2342 Description There is going to be a party to celebrate the 80-th ...
- poj 2342 Anniversary party 树形DP入门
题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加 ...
- POJ 2342 Anniversary party 树形DP基础题
题目链接:http://poj.org/problem?id=2342 题目大意:在一个公司中,每个职员有一个快乐值ai,现在要开一个party,邀请了一个员工就不可能邀请其直属上司,同理邀请了一个人 ...
- POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...
- TTTTTTTTTTT hdu 1520 Anniversary party 生日party 树形dp第一题
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- POJ Anniversary party 树形DP
/* 树形dp: 给一颗树,要求一组节点,节点之间没有父子关系,并且使得所有的节点的权值和最大 对于每一个节点,我们有两种状态 dp[i][0]表示不选择节点i,以节点i为根的子树所能形成的节点集所能 ...
- POJ 3162 Walking Race 树形DP+线段树
给出一棵树,编号为1~n,给出数m 漂亮mm连续n天锻炼身体,每天会以节点i为起点,走到离i最远距离的节点 走了n天之后,mm想到知道自己这n天的锻炼效果 于是mm把这n天每一天走的距离记录在一起,成 ...
- POJ 2342 Anniversary party (树dp)
题目链接:http://poj.org/problem?id=2342 有n个人,每个人有活跃值.下面n-1行u和v表示u的上司是v,有直接上司和下属的关系不能同时参加party,问你party最大的 ...
- [poj2342]Anniversary party_树形dp
Anniversary party poj-2342 题目大意:没有上司的舞会原题. 注释:n<=6000,-127<=val<=128. 想法:其实就是最大点独立集.我们介绍树形d ...
随机推荐
- 关于Python 获取windows信息收集
收集一些Python操作windows的代码 (不管是自带的or第三方库)均来自网上 1.shutdown 操作 定时关机.重启.注销 #!/usr/bin/python #-*-coding:utf ...
- scala中的抽象类
scala中也有和java,c#类似的抽象类,抽象类会有部分实现,也有没有实现的方法定义.抽象类最大的特征是不能直接实例化.下面我们看个例子. abstract class Animal { def ...
- c语言运算符号的优先级
c语言运算符号的优先级 本文来自百度搜索只为查看方便 优先级等级口诀: 圆方括号.箭头一句号, 自增自减非反负.针强地址长度, 乘除,加减,再移位, 小等大等.等等不等, 八位与,七位异,六位或,五与 ...
- Dwz下拉菜单的二级联动
在DWZ文档中对组合框combox的是这样描述的: 在传统的select 用class 定义:class=”combox”, html 扩展:保留原有属性name, 增加了属性:ref. ref 属 ...
- visibility和display的异同
都有隐藏节点的作用. visibility:hidden; display:none; (1)visibility 规定了元素是否可见,即使不可见也会占用上面的空间,在这里就是在指它与display的 ...
- 梳理源码中 View 的工作原理
欢迎Follow我的GitHub, 关注我的掘金. 在View的工作过程中, 执行三大流程完成显示, 测量(measure)流程, 布局(layout)流程, 绘制(draw)流程. 从perform ...
- blade用法
一.blade条件判断,foreach循环写法 @if(isset($fileInfo) && !empty($fileInfo)) @foreach($fileInfo as $k) ...
- appium运行报错.<init>(Lorg/openqa/selenium/remote/ErrorCodes;Z)V
最近这几天就在学习appium,搭建环境就耗费了很多时间,不得不承认自己够笨的了,然后我把环境搭建好,写完脚本的时候,就报这个错了,当时是从某个群里直接下载的demo,不得不吐槽说,够坑的,是能跑通, ...
- hdu 3518 Boring counting 后缀数组基础题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Fzu月赛11 老S的旅行计划 dij
Description 老S在某城市生活的非常不自在,想趁着ICPC举办期间在省内转转.已知老S所在的省有N个城市,M条无向边(对于某一对结点可能出现重边).由于省内的交通相当糟糕,通过某条边所需要花 ...