luogu 没有上司的舞会
来源:互联网 发布:视频大数据分析系统 编辑:程序博客网 时间:2024/05/13 02:30
题目
#include<cstdio>#include<algorithm>using namespace std;int dp[6005][2]; //dp[i][1]表示以 i 为根节点的子树中, 选取 i 的最优值; //dp[i][0]表示以 i 为根节点的子树中, 不取 i 的最优值.int dgr[6005],head[6005],pre[6005];void DP(int x){ for(int i=head[x];i;i=pre[i]) { DP(i); dp[x][0]+=max(dp[i][0],dp[i][1]); dp[x][1]+=dp[i][0]; }}int main(){ int n,root; scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%d",&dp[i][1]); } int x,y; scanf("%d%d",&x,&y); while(x) { pre[x]=head[y]; head[y]=x; ++dgr[x]; scanf("%d%d",&x,&y); } for(int i=1;i<=n;++i) if(dgr[i]==0) { root=i; break; } DP(root); printf("%d\n",max(dp[root][0],dp[root][1])); return 0;}
阅读全文
1 0
- luogu 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 没有上司的舞会
- 1380 没有上司的舞会
- 1380 没有上司的舞会
- Codevs1380 没有上司的舞会
- codevs 没有上司的舞会
- codevs1380 没有上司的舞会
- [tyvj1052]没有上司的舞会
- 【u024】没有上司的舞会
- 货车运输
- Maven之(三)Maven插件
- 014 方程组的通解 方法一:通解方程组 方法二:基础解析解
- luogu 选课
- Maven之(四)Maven命令
- luogu 没有上司的舞会
- Dijkstra算法及其堆优化
- Maven之(五)Maven仓库
- 关于 线段树 下传(AC) 不做标记 下传(T3)模板洛谷p3372
- 11.7计划
- mysql的双机热备
- WinForm基础控件---登陆实例
- ASP.NET WebApi 图片上传
- 鸣人的影分身