• [POJ 1463] Strategic Game


    [题目链接]

               http://poj.org/problem?id=1463

    [算法]

           树形DP

    [代码]

           

    #include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cerrno>
    #include <clocale>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <limits>
    #include <list>
    #include <map>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <utility>
    #include <vector>
    #include <cwchar>
    #include <cwctype>
    #include <stack>
    #include <limits.h>
    using namespace std;
    #define MAXN 1510
    
    int i,n,tot,u,s,v;
    int f[MAXN][2];
    int head[MAXN];
    
    struct Edge
    {
            int to,nxt;
    } e[MAXN << 1];
    inline void addedge(int u,int v)
    {
            tot++;
            e[tot] = (Edge){v,head[u]};
            head[u] = tot;    
    }
    inline void dp(int u,int fa)
    {
            int i,v;
            f[u][0] = 0;
            f[u][1] = 1;
            for (i = head[u]; i; i = e[i].nxt)
            {
                    v = e[i].to;
                    if (v == fa) continue;
                    dp(v,u);
                    f[u][1] += min(f[v][0],f[v][1]);
                    f[u][0] += f[v][1]; 
            }
    }
    
    int main() 
    {
            
            while (scanf("%d",&n) != EOF)
            {
                    tot = 0;
                    for (i = 0; i < n; i++) head[i] = 0;
                    for (i = 1; i <= n; i++)
                    {
                            scanf("%d : (%d)",&u,&s);
                            while (s--)
                            {
                                    scanf("%d",&v);
                                    addedge(u,v);
                                    addedge(v,u);        
                            }    
                    }    
                    dp(0,-1);
                    printf("%d
    ",min(f[0][0],f[0][1]));
            }
            
            return 0;
        
    }
  • 相关阅读:
    JDE函数--获取当前登录人的描述
    JDE报表开发笔记(R5537011 收货校验统计表)
    JDE函数--GetUDC(B函数)
    JDE隐藏Constant等(Hide Object)
    Oracle “dba_tables”介绍
    word2013设置页面边框
    makefile--#的不正确使用
    CICS定时
    程序的命名
    UE上传到FTP,会多出些字符
  • 原文地址:https://www.cnblogs.com/evenbao/p/9354066.html
Copyright © 2020-2023  润新知