poj 2342 Anniversary party
题目链接:http://poj.org/problem?id=2342
题意:读题很容易懂,这里不做介绍。
解法:树形DP之路的第一道题。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=;
int n;
int f[maxn][],vis[maxn];
int father[maxn];
void dfs(int root)
{
vis[root]=;
for (int i= ;i<=n ;i++)
{
if (!vis[i] && father[i]==root)
{
dfs(i);
f[root][] += max(f[i][],f[i][]);
f[root][] += f[i][];
}
}
}
int main()
{
while (cin>>n)
{
memset(f,,sizeof(f));
memset(vis,,sizeof(vis));
for (int i= ;i<=n ;i++) father[i]=i;
for (int i= ;i<=n ;i++) cin>>f[i][];
int a,b;
int root;
while (cin>>a>>b)
{
if (!a && !b) break;
father[a]=b;
}
for (int i= ;i<=n ;i++) if (father[i]==i) root=i;
dfs(root);
cout<<max(f[root][],f[root][])<<endl;
}
return ;
}
poj 2342 Anniversary party的更多相关文章
- 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 ...
- DP Intro - poj 2342 Anniversary party
今天开始做老师给的专辑,打开DP专辑 A题 Rebuilding Roads 直接不会了,发现是树形DP,百度了下了该题,看了老半天看不懂,想死的冲动都有了~~~~ 最后百度了下,树形DP入门,找到了 ...
- 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 有n个人,每个人有活跃值.下面n-1行u和v表示u的上司是v,有直接上司和下属的关系不能同时参加party,问你party最大的 ...
- 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 Anniversary party(树形dp)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7230 Accepted: 4162 ...
- poj 2342 Anniversary party 简单树形dp
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3862 Accepted: 2171 ...
- [ACM] POJ 2342 Anniversary party (树DP获得冠军)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4410 Accepted: 2496 ...
随机推荐
- PHP+ajax聊天室源码!支持长轮循跟定时请求两种
var lastID = "1";//声明上次取回的消息的ID var isposted = false; var mGetTime;//设置setTimeout的返回值 // ...
- rest api设计[资源]
web开发资源列表 http://www.bentobox.io/ rest api资源 Designing an API http://www.vinaysahni.com/best-practic ...
- SVG矢量图--爱心
aixin.xml: <!-- height:width=viewportHeight:viewportWidth --> <vector xmlns:android="h ...
- i++与++i的误解
javap -c xx.class {i=0i=i++}0: bipush 02: istore_1 stack ->var13: iload_1 var1->stack4: iinc 1 ...
- HTML5 API 之 history
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 菜鸟学习Struts——总结
一.原理 客户端请求到ActionSeverlet,ActionSeverlet负责截URL进行分发分发到每一个Action上,Action负责和Model打交道然后把相关信息返回到ActionSev ...
- hdu 1622 Trees on the level
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1622 小白书上的题... #include<algorithm> #include< ...
- 三种嵌入式web服务器(Boa / lighttpd / shttpd)的 linux移植笔记
一:移植Boa(web服务器)到嵌入式Linux系统 一.Boa程序的移植 1.下载Boa源码 下载地址: http://www.boa.org/ 目前最新发行版本: 0.94.13 ...
- Object C学习笔记2-NSLog 格式化输出数据
1 . 几种常用类型变量声明 int i =10; BOOL isShow=YES; BOOL isShow=1; float f = 3.1415926; char a =120; NSString ...
- Effective Objective-C 2.0之Note.04
“类族”(class cluster)是一种很有用的模式(pattern),可以隐藏“抽象基类”(abstract base class)背后的实现细节.Objective-C的系统框架中普遍使用此模 ...