洛谷2633 王后万岁
来源:互联网 发布:美国失业金数据公布 编辑:程序博客网 时间:2024/04/29 10:13
题目:http://www.luogu.org/problem/show?pid=2633
分析:DP
代码:
#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int Tmax=16005;int n,data[Tmax],ans=-2147483640;vector<int> G[Tmax];int dp(int x,int fa){ int i,len=G[x].size(),tmp,sum=data[x],to; for(i=0;i<len;i++) { to=G[x][i]; if(to==fa) continue; tmp=dp(to,x); if(tmp>0) sum+=tmp; } ans=max(ans,sum); return sum;}int main(){ int i,u,v; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&data[i]); for(i=1;i<n;i++) { scanf("%d%d",&u,&v); G[u].push_back(v); G[v].push_back(u); } ans=max(ans,dp(1,0)); printf("%d",ans); return 0;}
0 0
- 洛谷2633 王后万岁
- 洛谷 P2633 王后万岁
- 洛谷 P2633 王后万岁
- 梦想万岁!
- 中华人民共和国万岁
- Hooray 万岁!
- 一个人万岁?
- 意大利万岁?
- 理解万岁
- 宽带万岁
- LAMP万岁
- 一个人万岁!
- 正义万岁
- 生命万岁
- 祖国万岁!
- 友谊万岁
- hosts万岁
- 理解万岁
- iOS图片选择的优化与封装
- FMDB的使用
- 洛谷2622 关灯问题II
- (NO.00002)iOS游戏精灵战争雏形(七)
- jsp的内置对象有下列这些
- 洛谷2633 王后万岁
- 一个轻量级的c编写的php接口平台框架
- HDU 2049 错排变种
- CoreData的使用
- 杭电1282-回文
- CentOS6.3虚拟机配置安装
- ThinkPHP如何禁止直接通过路径访问
- java同步器之F4
- 01背包入门啦………