/*
【题意】 给定一棵树,标记一节点,则与该节点所连的边都被标记,问最少需要标记多少个节点使得所有边都被标记;
或者说给定一个树型城堡,在交叉路口放一个士兵,则与该路口相连的路都被守住,
问最少需要派遣多少个士兵来守住这个城堡 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. mysql 数据库使用

    1. 常用命令 2. 创建表 create table test ( test_id int, test_price decimal ); 或者 create table test2 as selec ...

  2. BZOJ 1597 [Usaco2008 Mar]土地购买:斜率优化dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1597 题意: 有n块矩形土地,长为a[i],宽为b[i]. FJ想要将这n块土地全部买下来 ...

  3. css3 多列布局使用

    css3的出现,解决了不少前端的问题,比如动画,圆角等: 这里总结一下css3 的多列布局: w3c上给出了很多属性: 我们一般用到column-count.column-gap.column-wid ...

  4. HTML5学习笔记——1

    1.视频 <vedio src  controls  height width autoplay loop preload > </vedio> <source src ...

  5. spring 4 + jpa(hibernate 3/4) + spring mvc 多数据源配置

    先从persistence.xml开始: <?xml version=”1.0″ encoding=”UTF-8″?><persistence version=”2.1″ xmlns ...

  6. iis_rewrite3突然无法使用(因为它过期啦)

    转自http://www.b1y.cn/post/216.html ISAPI_Rewrite3完全版会有45天的试用期,过期了需要99美元进行够买,网上有很多破解版的,方法如下: 1.先从官网下一个 ...

  7. [原]NYOJ-A*B Problem II-623

    大学生程序代写 A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相 ...

  8. C++ STL, set用法。 待更新zzzzz

    set集合容器:实现了红黑树的平衡二叉检索树的数据结构,插入元素时,它会自动调整二叉树的排列,把元素放到适当的位置,以保证每个子树根节点键值大于左子树所有节点的键值,小于右子树所有节点的键值:另外,还 ...

  9. ACM学习历程—UESTC 1218 Pick The Sticks(动态规划)(2015CCPC D)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 题目大意就是求n根木棒能不能放进一个容器里,乍一看像01背包,但是容器的两端可以溢出容器,只要两端的木 ...

  10. bzoj 3796: Mushroom追妹纸 AC自动机+后缀自动机+dp

    题目大意: 给定三个字符串s1,s2,s3,求一个字符串w满足: w是s1的子串 w是s2的子串 s3不是w的子串 w的长度应尽可能大 题解: 首先我们可以用AC自动机找出s3在s1,s2中出现的位置 ...