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(二分图最大匹配)
题意:给你一个图,图里有墙壁和空地,空地可以放置一台机关枪,机关枪可以朝着四个方向发射,子弹不能穿透墙壁,但是射程无限,机关枪会被损坏如果被另一台机关枪的子弹打到,问你最多能放置多少台机关枪: 解题思 ...
随机推荐
- etcd -> Highly-avaliable key value store for shared configuration and service discovery
The name "etcd" originated from two ideas, the unix "/etc" folder and "d&qu ...
- HDU 之 I Hate It
I Hate It Time Limit ...
- VNC服务安装、配置与使用
原帖地址: http://blog.itpub.net/519536/viewspace-607549/ 该文档配置环境是RHEL,不同系统可能会有差别,本人测试过centos,ubuntu 1.确认 ...
- mysql 事件(Event) 总结
1 事件简介 事件(event)是MySQL在相应的时刻调用的过程式数据库对象.一个事件可调用一次,也可周期性的启动,它由一个特定的线程来管理的,也就是所谓的“事件调度器”. 事件和触发器类似,都是在 ...
- Android 动态权限申请
package com.dragon.android.permissionrequest; import android.Manifest; import android.content.Dialog ...
- R Customizing graphics
Customizing graphics GraphicsLaTeXLattice (Treillis) plots In this chapter (it tends to be overly co ...
- 模拟Windows任务管理器CPU使用率的动态折线图-农夫山泉
Delphi的TCanvas类可以实现各种复杂的图形输出功能,基于近期项目的需求,利用它实现了一个很炫的动态折线图(模拟了资源管理器中CPU使用率的折线图),可以直观地展现出数值的实时变化情况. 这段 ...
- 十一 Django框架,Session
Django中默认支持Session,其内部提供了5种类型的Session供开发者使用: 1.数据库(默认)2.缓存3.文件4.缓存+数据库5.加密cookie 1.数据库Session,保存在数据库 ...
- Raft 为什么是更易理解的分布式一致性算法——(1)Leader在时,由Leader向Follower同步日志 (2)Leader挂掉了,选一个新Leader,Leader选举算法。
转自:http://www.cnblogs.com/mindwind/p/5231986.html Raft 协议的易理解性描述 虽然 Raft 的论文比 Paxos 简单版论文还容易读了,但论文依然 ...
- hdu-5867 Water problem(水题)
题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...