zoukankan      html  css  js  c++  java
  • P2016 战略游戏

    树形DP,求最小点覆盖集

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #define maxn 1510
    
    using namespace std;
    
    struct node
    {
        int ed,nxt;
    };
    node edge[maxn<<1];
    int n,m,cnt,first[maxn];
    int dp[maxn][2];
    
    inline void add_edge(int s,int e)
    {
        ++cnt;
        edge[cnt].ed=e;
        edge[cnt].nxt=first[s];
        first[s]=cnt;
        return;
    }
    
    inline void dfs(int now,int fa)
    {
        for(register int i=first[now];i;i=edge[i].nxt)
        {
            int e=edge[i].ed;
            if(e!=fa)
            {
                dfs(e,now);
                dp[now][0]+=dp[e][1];
                dp[now][1]+=min(dp[e][0],dp[e][1]);
            }
        }
        dp[now][1]+=1;
        return;
    }
    
    int main()
    {
        scanf("%d",&n);
        for(register int i=1;i<=n;++i)
        {
            int now,tot;
            scanf("%d%d",&now,&tot);
            now++;
             for(register int j=1;j<=tot;++j)
             {
                 int e;
                 scanf("%d",&e);
                 add_edge(now,e+1);
                add_edge(e+1,now); 
            }
        }
        dfs(1,0);
        printf("%d
    ",min(dp[1][0],dp[1][1]));
        return 0;
    } 
  • 相关阅读:
    Linux_day01_primaryCommand
    Variational auto-encoder VS auto-encoder
    python yield generator 详解
    Paper Writing
    DTU_AI lecture 09
    DTU_AI lecture 08
    Attention mechanism
    Energy Journals
    TF + pytorch学习
    expRNN
  • 原文地址:https://www.cnblogs.com/Hoyoak/p/11831301.html
Copyright © 2011-2022 走看看