/*
【题意】 给定一棵树,标记一节点,则与该节点所连的边都被标记,问最少需要标记多少个节点使得所有边都被标记;
或者说给定一个树型城堡,在交叉路口放一个士兵,则与该路口相连的路都被守住,
问最少需要派遣多少个士兵来守住这个城堡 dp[father].yes= ( min(dp[child].yes,dp[child].no) 之和)
dp[father].yes=( min(dp[child].yes,dp[child].no) 之和) */
#include<stdio.h>
#include<string.h> struct node
{
int father,brother,child;
int yes,no; void init()
{
father=brother=child=0;
yes=1;
no=0;
}
}t[1505]; bool use[1505];
int min(int x,int y)
{
if(x<y) return x;
return y;
} void dfs(int root)
{
int child=t[root].child;
while(child)
{
dfs(child);
t[root].yes+=min(t[child].yes,t[child].no);
t[root].no+=t[child].yes;
child=t[child].brother;
}
}
/*
void dfs(int root)
{
int child=t[root].child;
while(child)
{
dfs(child);
printf("root%d %d",root,child);
child=t[child].brother;
}
}*/ int main()
{
int n,Root,root,cnt,j;
while(scanf("%d",&n)!=EOF)
{
memset(use,0,sizeof(use)); //int Root; for(int i=1;i<=n;i++)
{
scanf("%d:(%d)",&root,&cnt),root++;
if(i==1) Root=root; if(!use[root])
{
t[root].init();
use[root]=1;
} while(cnt--)
{
scanf("%d",&j),j++;
if(!use[j])
{
t[j].init();
use[j]=1;
}
t[j].brother=t[root].child;
t[j].father=root;
t[root].child=j;
}
} dfs(Root); printf("%d\n",min(t[Root].no,t[Root].yes)); } return 0;
}

hdu1054的更多相关文章

  1. hdu1054(二分图匹配)

    题意很简单,在一颗树上找最小点覆盖. 将树染成黑白两色,构成一张二分图,然后最大匹配==最小点覆盖即可,所以一次匈牙利就可以求出来了 hdu1054 #include <iostream> ...

  2. HDU1054 Strategic Game —— 最小点覆盖 or 树形DP

    题目链接:https://vjudge.net/problem/HDU-1054 Strategic Game Time Limit: 20000/10000 MS (Java/Others)     ...

  3. HDU1054 Strategic Game——匈牙利算法

    Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...

  4. hdu1054 树形dp&&二分图

    B - Strategic Game Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  5. hdu---(1054)Strategic Game(最小覆盖边)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. hdu1054 树状dp

    B - 树形dp Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:10000KB     64bit ...

  7. hdu1054(最小顶点覆盖)

    传送门:Strategic Game 题意:用尽量少的顶点来覆盖所有的边. 分析:最小顶点覆盖裸题,最小顶点覆盖=最大匹配数(双向图)/2. #include <cstdio> #incl ...

  8. hdu1054最小顶点覆盖

    最小定点覆盖是指这样一种情况: 图G的顶点覆盖是一个顶点集合V,使得G中的每一条边都接触V中的至少一个顶点.我们称集合V覆盖了G的边.最小顶点覆盖是用最少的顶点来覆盖所有的边.顶点覆盖数是最小顶点覆盖 ...

  9. hdu1054 Strategic Game 树形DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 思路:树形DP,用二分匹配也能解决 定义dp[root][1],表示以root 为根结点的子树且 ...

  10. hdu-1054(二分图最大匹配)

    题意:给你一个图,图里有墙壁和空地,空地可以放置一台机关枪,机关枪可以朝着四个方向发射,子弹不能穿透墙壁,但是射程无限,机关枪会被损坏如果被另一台机关枪的子弹打到,问你最多能放置多少台机关枪: 解题思 ...

随机推荐

  1. bagging与boosting集成学习、随机森林

    主要内容: 一.bagging.boosting集成学习 二.随机森林 一.bagging.boosting集成学习 1.bagging: 从原始样本集中独立地进行k轮抽取,生成训练集.每轮从原始样本 ...

  2. 最小生成树prim算法 POJ2031

    #include<iostream> #include<algorithm> #include<string.h> #include<ctype.h> ...

  3. Oracle备份和恢复

    --什么是脱机备份 脱机备份也叫冷备份,首先管理员使用 shutdown immediate 命令关闭数据库的服务. 之后复制需要的文件,包括数据文件和控制文件等相关内容复制到磁盘的其他位置.当 数据 ...

  4. jQuery-中的事件

    [jQuery中的事件] javascript和html之间的交互是通过用户和浏览器操作页面时引发的事件来处理的,虽然传统的javascript能完成这些交互,但事jQuery增加并扩充了基本事件处理 ...

  5. JQuery表单验证插件EasyValidator

    本插件的宗旨是:用户无需写一行JS验证代码,只需在要验证的表单中加入相应的验证属性即可,让验证功能易维护,可扩展,更容易上手. DEMO中已经包含了常用的正则表达式,可以直接复用,为了考虑扩展性,所以 ...

  6. MFC实现COM组件

    一般而言,ATL实现了对COM组件最好的支持,所以不用MFC实现COM组件.但是MFC实际上也是可以实现COM组件的. 一.MFC DLL优点: MFC com组件可以将MFC的类型作为参数进行传递, ...

  7. codeforces 632A A. Grandma Laura and Apples(暴力)

    A. Grandma Laura and Apples time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. 《java编程思想》:字符串

    1.String对象是不可变的,String类中每个看起来会修改String值的方法,实际上都是创建了一个新的String对象,来包含修改后的内容,所以在对String修改后,想打印新的值,可以直接打 ...

  9. git克隆某一个branch

    git clone -b <branch> <remote_repo> 例如: git clone -b 指定的分支名字

  10. [原]NYOJ-大数阶乘-28

    大学生程序代写 //http://acm.nyist.net/JudgeOnline/problem.php?pid=28 /*题目28题目信息运行结果本题排行讨论区大数阶乘 时间限制:3000 ms ...