[HDU 1520] Anniversary party
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6078 Accepted Submission(s): 2752
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
树形DP入门题目、、
加了一个输入输出外挂、、无耻地飘进首页、、
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <iterator>
#include <cstring>
#include <string>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define INF 0x7fffffff
#define ll long long
#define N 6010 struct Edge
{
int to,next;
}edge[N<<];
int head[N],tot;
int n;
int f[N];
int val[N];
int vis[N];
int dp[N][]; template <class T>
inline bool input(T &ret)
{
char c; int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret=ret*+(c-'');
ret*=sgn;
return ;
} inline void out(int x)
{
if(x>) out(x/);
putchar(x%+'');
} void init()
{
tot=;
memset(head,-,sizeof(head));
memset(f,,sizeof(f));
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis));
} void add(int x,int y)
{
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot++;
} void dfs(int u)
{
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].to;
if(!vis[v])
{
vis[v]=;
dfs(v);
dp[u][]+=dp[v][];
dp[u][]+=max(dp[v][],dp[v][]);
}
}
dp[u][]+=val[u];
} int main()
{
int i;
while(input(n))
{
init();
for(i=;i<=n;i++)
{
input(val[i]);
}
int a,b;
while()
{
input(a);
input(b);
if(a+b==) break;
f[a]=b;
add(b,a);
}
int root=;
while(f[root])
{
root=f[root];
}
vis[root]=;
dfs(root);
out(max(dp[root][],dp[root][]));
putchar('\n');
}
return ;
}
[HDU 1520] 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 ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- HDU 1520.Anniversary party 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- hdu 1520 Anniversary party || codevs 1380 树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1520 Anniversary party(入门树形DP)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6926 Accepted: 3985 ...
- 题解报告:hdu 1520 Anniversary party(树形dp入门)
Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...
随机推荐
- [Guava官方文档翻译] 2.使用和避免使用null (Using And Avoiding Null Explained)
本文地址:http://www.cnblogs.com/hamhog/p/3536647.html "null很恶心." -Doug Lea "这是一个令我追悔莫及的错误 ...
- 九度OJ 1120 全排列 -- 实现C++STL中next_permutation()
题目地址:http://ac.jobdu.com/problem.php?pid=1120 题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' ...
- php 加密解密方法2
<?php /* * @param $string 要加密或解决的字符串 * @param $operation 加密/解密 ENCODE加密, DECODE 解密 * @param $key ...
- Android开发系列之调用WebService
我在学习Android开发过程中遇到的第一个疑问就是Android客户端是怎么跟服务器数据库进行交互的呢?这个问题是我当初初次接触Android时所困扰我的一个很大的问题,直到几年前的一天,我突然想到 ...
- DIV CSS布局中position属性用法深入探究
本文向大家描述一下DIV CSS布局中的position属性的用法,position属性主要有四种属性值,任何元素的默认position的属性值均是static,静态.这节课主要讲讲relative( ...
- android实现视频图片取缩略图
取缩略图不等同于缩放图片. 缩放图片是保持不失真的情况下缩放处理,并进行平滑处理. 缩略图则不然,允许失真,目的只是取出图片的轮廓. 保存Bitmap图片 private void saveBitma ...
- Vijos P1061 迎春舞会之三人组舞 DP
题目链接:https://vijos.org/p/1061 n个人选出3*m人,排成m组,每组3人. 站的队形——较矮的2个人站两侧,最高的站中间. 从对称学角度来欣赏,左右两个人的身高越接近,则这一 ...
- spring mvc处理流程概述
大部分Java应用都是Web应用,展现层是Web应用不可忽略的重要环节.Spring为展现层提供了一个优秀的Web框架-Spring MVC.和众多其他Web框架一样,它基于MVC设计理念,此外,它采 ...
- mapreduce 多路输出
Streaming支持多路输出(SuffixMultipleTextOutputFormat) 如下示例: hadoop streaming \ -input /home/mr/data/test_t ...
- Ext.QuickTips.init();
在Extjs的组件需要提示框时往往需要此语句. 首先,Ext.QuickTips是什么? 在Ext JS 4.2.0 的API中可以查到,注意在其他的Extjs版本以下查不到,这是因为在其他版本Ext ...