Anniversary Party
Time limit: 0.5 second
Background
Problem
Input
Output
Sample
input | output |
---|---|
7 |
5 |
算是比较基础的树形dp的题吧 ,qwq ,先要寻找根节点 。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std ;
const int inf = << , maxn = + ;
int n ,fen[maxn] , f[maxn][] , head[maxn] , cnt , ru[maxn] ;
struct id
{
int nxt , to ;
} edge[maxn] ; void add( int u , int v )
{
edge[++cnt].to = v , edge[cnt].nxt = head[u] ;
head[u] = cnt ;
} void Init( )
{
scanf( "%d" , &n ) ; int l ,k ;
for( int x = ; x <= n ; ++x ) scanf( "%d" , fen+x ) ;
while( )
{
scanf( "%d%d" , &l , &k ) ;
if( l == k && k == ) break ;
add( k , l ) ;
ru[l]++ ;
}
} int dfs( int u , int use )
{
if( ~f[u][use] ) return f[u][use] ;
int v = ; f[u][use] = ;
for( int x = head[u] ; x ; x = edge[x].nxt )
{
v = edge[x].to ;
if( use == ) f[u][use] += dfs( v , ) ;
else
{
f[u][use] += max( dfs(v , ) , dfs(v , ) ) ;
}
}
if( use == ) f[u][use] += fen[u] ;
return f[u][use] ;
} void Solve( )
{
int ans = ;memset( f , - , sizeof(f) ) ;
for( int x = ; x <= n ; ++x )
{
if( !ru[x] )
{
// cout<<x<<endl;
ans = max( ans , max( dfs( x , ) , dfs( x , ) ) ) ;
}
}
printf( "%d\n" , ans ) ;
} int main( )
{
Init( ) ;
Solve( ) ;
return ;
}
Anniversary Party的更多相关文章
- (UWP开发)基于Windows10 Anniversary SDK创造出位于可视化层的DropShadow
Windows.UI.Composition API是可以从任何通用Windows平台应用程序调用的声明性保留模式API,从而可以直接在应用程序中创建合成对象.动画和效果. Composition A ...
- POJ 2342 Anniversary party(树形dp)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7230 Accepted: 4162 ...
- 微软四十周年 Microsoft’s 40th anniversary
比尔-盖茨在4月3日给微软全体员工写了这封邮件,原文是英文,我们翻译了中文.图片是后加上的. 明天将是特殊的一天:微软的40周年纪念日. Tomorrow is a special day: Micr ...
- HDOJ 1520 Anniversary party
树形DP....在树上做DP....不应该是猴子干的事吗? Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu1520 树形dp Anniversary party
A - Anniversary party Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- hdu 1520 Anniversary party 基础树dp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 【Poj】 p2342 Anniversary party(树形DP第一道)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5523 Accepted: 3169 ...
- poj 2342 Anniversary party 简单树形dp
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3862 Accepted: 2171 ...
- BestCoder 1st Anniversary B.Hidden String DFS
B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...
- HDU 1520:Anniversary party(树形DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Problem Description There i ...
随机推荐
- Oracle课堂实验一“表的使用”代码。
--创建本地管理表空间CustomerTBSCREATE TABLESPACE CustomerTBS DATAFILE 'd:\Oracle11\product\11.2.0\ora ...
- django之JavaScript的简单学习2
前言:ajax预备知识:json进阶 1.JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON是用字符串来表示Javascript对象: 请大家记住一 ...
- ul动态增加li
--> aaa bbb <%@ page language="java" import="java.util.*" pageEncoding=&qu ...
- 在vmware 6.5+ubuntu12.04上安装VMware tools出现问题的分析
笔者已经写了一篇关于安装"VMware Tools",以实现文件共享的文章,那篇文章对于你实现共享操作是足够了, 所以,倘若你赶时间不如直接去在虚拟机的linux中利用VMware ...
- Swift开发之 ---- Swift宏定义
swift中没有了#Define这种宏定义了,可以用let来声明常量来取代,判断当前系统版本 let IS_IOS7 = (UIDevice.currentDevice().systemVersion ...
- 《无懈可击的Web设计》_灵活的文字
常见的方法 body{ font-size:12px; } 使用像素单位的优点: 不管使用哪种浏览器或者设备来查看,文字看起来都大小一致. 为什么这么做不是无懈可击的? 以像素为单位设定文字大小之后, ...
- Analysis Guidelines
This section describes some best practices for analysis. These practices come from experience of ana ...
- [cocos2d] 显示状态与文字
前言: 对于显示数值与文字一般有三种方式可以使用: CCLabelTTF .CCLabelBMFont .CCLabelAtlas 详细区别可参考:cocos2d 中添加显示文字的三种方式(CCLab ...
- [译]GotW #2: Temporary Objects
不必要的和(或)临时的变量经常是罪魁祸首,它让你在程序性能方面的努力功亏一篑.如何才能识别出它们然后避免它们呢? Problem JG Question: 1. 什么是临时变量? Guru Q ...
- perl 监控mysql 事务和锁
use DBI; use Net::SMTP; use HTTP::Date qw(time2iso str2time time2iso time2isoz); # mail_user should ...