poj-2342-简单树形dp
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10388 | Accepted: 5943 |
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<bitset>
#include<cstring>
#include<cstdio>
using namespace std;
#define inf 0x3f3f3f3f
int fa[];
int son[];
int next[];
int f[][];
int c[];
int N,root;
void dfs(int u,int father){
f[u][]=c[u];
f[u][]=;
int s=;
for(int i=son[u];i;i=next[i]){
if(i==father) continue;
dfs(i,u);
if(f[i][]>) f[u][]+=f[i][];
f[u][]+=max(,max(f[i][],f[i][]));
}
}
int main()
{
int i,j,k;
int u,v;
while(cin>>N){
if(N==){
cin>>N;
break;
}
memset(fa,,sizeof(fa));
memset(son,,sizeof(son));
memset(next,,sizeof(next));
for(i=;i<=N;++i) scanf("%d",c+i);
for(i=;i<N;++i){
scanf("%d%d",&u,&v);
fa[u]=v;
next[u]=son[v];
son[v]=u;
}
for(i=;i<=N;++i)
if(!fa[i]) {root=i;break;}
dfs(root,);
cout<<max(f[root][],f[root][])<<endl;
}
return ;
}
poj-2342-简单树形dp的更多相关文章
- Anniversary party POJ - 2342 (树形DP)
题目链接: POJ - 2342 题目大意:给你n个人,然后每个人的重要性,以及两个人之间的附属关系,当上属选择的时候,他的下属不能选择,只要是两个人不互相冲突即可.然后问你以最高领导为起始点的关系 ...
- POJ 2342 (树形DP)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3863 Accepted: 2172 ...
- [poj 2342]简单树dp
题目链接:http://poj.org/problem?id=2342 dp[i][0/1]表示以i为根的子树,选或不选根,所能得到的最大rating和. 显然 dp[i][0]=∑max(dp[so ...
- POJ 2342 Label:树形dp
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6955 Accepted: 4003 ...
- poj 2342 Anniversary party 简单树形dp
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3862 Accepted: 2171 ...
- [POJ 1155] TELE (树形dp)
题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每 ...
- hdu4705 Y 简单树形DP 2013多校训练第十场 J题
题意:求一棵树中不在一条链中的三个点的对数. 转化一下,用总对数减去在一条链上的三点对数即可. 考虑经过根节点,然后可能是不同的子树中各选一个:或者是子树中选一个,然后当前节点为根的子树以外的节点选一 ...
- Apple Tree POJ - 2486 (树形dp)
题目链接: D - 树形dp POJ - 2486 题目大意:一颗树,n个点(1-n),n-1条边,每个点上有一个权值,求从1出发,走V步,最多能遍历到的权值 学习网址:https://blog.c ...
- POJ 3107.Godfather 树形dp
Godfather Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7536 Accepted: 2659 Descrip ...
- [10.27_P2] 统计损失 (简单树形DP)
树形DP 简单题 Description 给定一棵树,每个节点有一个值.对于一条路径,它的值为路径上所有点的值的乘积.求出树上所有路径的值的和. 注意:单个点也算一条路径. Input 第 1 行一个 ...
随机推荐
- windows平台mongoDB安装配置
一.首先安装mongodb 1.官网下载mongoDB:http://www.mongodb.org/downloads,选择windows平台.安装时,一路next就可以了.我安装在了F:\mong ...
- C++之旅(第一天)
基础知识 完全支持C语言 可以在C++引入C的头文件 #include <stdio.h> #include <iostream> int main() { } 输入和输出 C ...
- kivy sdl2 - ImportError: DLL load failed: 找不到指定的模块
from kivy.app import App from kivy.uix.button import Button class TestApp(App): def build(self): ret ...
- Selenium+Python常见定位方法
参见官网:http://selenium-python.readthedocs.io/locating-elements.html 有多种策略来定位页面中的元素.你可以使用最适合你的情况.Seleni ...
- Linux 实时性能测试工具——Cyclictest
Cyclictest 是 rt-tests 下的一个测试工具,也是rt-tests 下使用最广泛的测试工具,一般主要用来测试使用内核的延迟,从而判断内核的实时性. 1.2 cyclictest 安装 ...
- Axure的总结
1.Axure的用途 Axure RP 能帮助网站需求设计者,快捷而简便的创建基于网站构架图的带注释页面示意图.操作流程图.以及交互设计,并可自动生成用于演示的网页文件和规格文件,以提供演示 ...
- Swoole学习(六)Swoole之定时器的创建与清除
环境:Centos6.4,PHP环境:PHP7,Swoole2.1(在指定的时间后执行函数,需要1.7.7或更高版本) <?php //----------------------------- ...
- JAVA面试题整理(1)-基础
1.List 和 Set 的区别 共同点:它们都是Collection的子接口 区别: List:这个接口能够精准的记录每一个元素的插入位置(换句话说就是这个接口内容所有元素是按照顺序去保存的),使 ...
- ThinkPHP5执行流程分析
1.入口文件(tp5\public\index.php) 作用: 1)定义目录常量. 2)加载框架引导目录. 2.框架引导目录(tp5\thinkphp\start.php) 作用: 1)引导基础文件 ...
- HandyJSON第三方库的日常使用与错误记录
一.错误提示 1.更新Xcode10.2,Swift5.0出现错误提示 Undefined symbols for architecture x86_64: "_swift_getField ...