hdu1054
/*
【题意】 给定一棵树,标记一节点,则与该节点所连的边都被标记,问最少需要标记多少个节点使得所有边都被标记;
或者说给定一个树型城堡,在交叉路口放一个士兵,则与该路口相连的路都被守住,
问最少需要派遣多少个士兵来守住这个城堡 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的更多相关文章
- hdu1054(二分图匹配)
题意很简单,在一颗树上找最小点覆盖. 将树染成黑白两色,构成一张二分图,然后最大匹配==最小点覆盖即可,所以一次匈牙利就可以求出来了 hdu1054 #include <iostream> ...
- HDU1054 Strategic Game —— 最小点覆盖 or 树形DP
题目链接:https://vjudge.net/problem/HDU-1054 Strategic Game Time Limit: 20000/10000 MS (Java/Others) ...
- HDU1054 Strategic Game——匈牙利算法
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...
- hdu1054 树形dp&&二分图
B - Strategic Game Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu---(1054)Strategic Game(最小覆盖边)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu1054 树状dp
B - 树形dp Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:10000KB 64bit ...
- hdu1054(最小顶点覆盖)
传送门:Strategic Game 题意:用尽量少的顶点来覆盖所有的边. 分析:最小顶点覆盖裸题,最小顶点覆盖=最大匹配数(双向图)/2. #include <cstdio> #incl ...
- hdu1054最小顶点覆盖
最小定点覆盖是指这样一种情况: 图G的顶点覆盖是一个顶点集合V,使得G中的每一条边都接触V中的至少一个顶点.我们称集合V覆盖了G的边.最小顶点覆盖是用最少的顶点来覆盖所有的边.顶点覆盖数是最小顶点覆盖 ...
- hdu1054 Strategic Game 树形DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 思路:树形DP,用二分匹配也能解决 定义dp[root][1],表示以root 为根结点的子树且 ...
- hdu-1054(二分图最大匹配)
题意:给你一个图,图里有墙壁和空地,空地可以放置一台机关枪,机关枪可以朝着四个方向发射,子弹不能穿透墙壁,但是射程无限,机关枪会被损坏如果被另一台机关枪的子弹打到,问你最多能放置多少台机关枪: 解题思 ...
随机推荐
- EntityFramework 学习 一 Entity Relationships 实体的关系
下面,我们学习Entity Framework怎么管理实体间的关系 Entity Framework支持三种关系:一对一的关系.一对多的关系.多对多的关系 前面我们创建SchoolDB的实体数据模型, ...
- 格式化namenode时 报错 No Route to Host from node1/192.168.1.111 to node3:8485 failed on socket timeout exception: java.net.NoRouteToHostException: No route to host
// :: FATAL namenode.NameNode: Failed to start namenode. org.apache.hadoop.hdfs.qjournal.client.Quor ...
- python第一篇:Python 字符串编
Python字符串编码 字符串编码的前世今生 1. 一个字节由8个bit组成,所以1个字节能表示的最大数为255: 2. 计算机是美国人发明的,所以一个字节可以表示所有的字符了,所以ASCII就成为美 ...
- 程序以html形式发送邮件注意问题
1.样式要写在内部,不要单独定义样式 2.div 使用背景图片在有些浏览器中出不来这时候需要用: <table style="width: 640px" cellpaddin ...
- Linux课程---4、Linux目录结构及常用命令(目录结构)
Linux课程---4.Linux目录结构及常用命令(目录结构) 一.总结 一句话总结: 家目录:./root:root用户的家目录 能执行的程序:./bin:所有用户都能执行的程序:./sbin:只 ...
- java:Properties属性文件概念
java:Properties属性文件概念 在java之前的国际化程序中提出了一个属性文件的概念,属性文件的后缀是:*.properties,那么在java中提供了意个属性文件的专门操作类,Prope ...
- zookeeper+dubbo问题
1.java.lang.IllegalStateException: Context namespace element 'component-scan' and its parser class [ ...
- Compilation error 未完待续
1. code.cpp:1:21: fatal error: iostream : No such file or directory #include< iostream > ^ com ...
- java try中包含return语句,finally中的return语句返回顺序
//结论: finally 中的代码比 return 和 break 语句后执行 public static void main(String[] args) { int x=new Test.tes ...
- java中变量的分类
•按被声明的位置划分: –成员变量:方法外部.类的内部定义的变量 –局部变量:方法或语句块内部定义的变量 –注意:类外面(类对应的大括号外面)不能有变量的声明 •按所属的数据类型划分: ...