zoukankan      html  css  js  c++  java
  • HDU 1520 Anniversary party

    题意:n个人去参加聚会,其中有直接上下级关系的参加聚会会影响气氛,所以不能参加,每个人参加聚会都会有一个活跃度,现在要你计算从n个人中选择出一些人,使得本次聚会的活跃度最大

    输入数据:
    第一行一个N代表有N个人,然后是N个人每个人的活跃度。
    然后再N-1行, 每行两个数字,L K 代表 第K个员工是第L个人的上司。
     
     
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<map>
    using namespace std;
    typedef long long LL;
    const int INF = 1e9+7;
    const int maxn = 6010;
    const int MOD = 1e9+7;
    int n, dp[2][maxn], In[maxn];///dp[这个点是否选取][第n个点]
    vector<vector<int> > G;
    
    void TreeDp(int root)
    {
        int len = G[root].size();
        for(int i=0; i<len; i++)
        {
            int v = G[root][i];
            TreeDp(v);
            dp[0][root] += max(dp[0][v],dp[1][v]);
            dp[1][root] += dp[0][v];
        }
    }
    
    int main()
    {
        int a, b;
        while(scanf("%d", &n) != EOF)
        {
            G.clear();
            G.resize(n+5);
            memset(dp, 0, sizeof(dp));
            memset(In, 0, sizeof(In));
            for(int i=1; i<=n; i++)
                scanf("%d", &dp[1][i]);
    
            while(scanf("%d %d", &a, &b), a+b)
            {
                G[b].push_back(a);
                In[a] ++;
            }
            int root;
    
            for(int i=1; i<=n; i++)
                if(!In[i]) root = i;
    
            TreeDp(root);
    
            printf("%d
    ", max(dp[0][root],dp[1][root]));
    
        }
        return 0;
    }
  • 相关阅读:
    获取app下载链接
    查找文件的路径
    回忆基础:制作plist文件
    Ping++中的AlipaySDK和AlicloudUTDID冲突解决方案
    CocoaPods常用操作命令
    自签名配置HTTPS
    Instruments10 分析某个类中方法的执行时间
    iOS KVC/KVO
    iOS 系统架构及常用框架
    LINQ to SQLite完美解决方案
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4861339.html
Copyright © 2011-2022 走看看