LA 2038
Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on the nodes so that they can observe all the edges. Can you help him?
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
For example for the tree:

the solution is one soldier (at the node 1).
Input
The input file contains several data sets in text format. Each data set represents a tree with the following description:
- the number of nodes
- the description of each node in the following format:
node_identifier:(number_of_roads) node_identifier1 node_identifier2 � node_identifiernumber_of_roads
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n ≤ 1500). Every edge appears only once in the input data.
Output
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers).
Sample Input
4
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)
Sample Output
1
2 DP,每个点放士兵或者不放士兵两种状态,dp[i][0] += dp[v][1] dp[i][1] += min(dp[v][1],dp[v][0]);
0代表不放,1代表放。
LA 2038的更多相关文章
- LA 2038 最少点覆盖
题目链接:https://vjudge.net/problem/UVALive-2038 题意:我看了原题,lrj的书上题意写错了,应该是最少点覆盖,当然可以用最大匹配去做,由于是树形的: 可以树形D ...
- LA 2038 Strategic game(最小点覆盖,树形dp,二分匹配)
题意即求一个最小顶点覆盖. 对于没有孤立点的图G=(V,E),最大独立集+最小顶点覆盖= V.(往最大独立集加点) 问题可以变成求树上的最大独立集合. 每个结点的选择和其父节点选不选有关, dp(u, ...
- php 2038年问题
在mysql中存放日期时可以存放整数 (int), 而int可以存放的数据最大为4294967295(无符号), 而php最大为2147483647, 要显示一个大于2038年日期,该如何处理 ? ...
- HYSBZ 2038 莫队算法
小Z的袜子(hose) Time Limit:20000MS Memory Limit:265216KB 64bit IO Format:%lld & %llu Submit ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- BZOJ 2038: [2009国家集训队]小Z的袜子(hose) [莫队算法]【学习笔记】
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 7687 Solved: 3516[Subm ...
- BZOJ 2038: [2009国家集训队]小Z的袜子(hose)
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 7676 Solved: 3509[Subm ...
- [BZOJ 2038]小Z的袜子
传送门:BZOJ 2038 题意很明确,是在给定的区间内任意选取两个数,求选到两个相同的数的概率. 所以我们得首先统计在给定的区间内,相同的数对有多少对,那么这里就使用到了莫队算法.如果对莫队算法还不 ...
随机推荐
- 关于消除超长的case列表的一个思路
最近项目里面涉及和低层通信的一个模块,因为需要定义通信协议,然后一大堆指令,定义一个枚举的话就能看到几十上百的数据项,匹配操作的时候,那么问题来了,尼玛,这么多的case看着就头晕,就有了一个想法:怎 ...
- hdu 2425 Hiking Trip
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...
- UITextField 属性详解
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...
- 通过firefox+ProxySelector+dtunnel_lite实现代理上网
通过firefox+ProxySelector+dtunnel_lite实现代理上网 dtunnel_lite:http://dog-tunnel.tk/下载lite版本就可以 远端:./dtunne ...
- NewRelicAgent(CustomAnalyticEvent.cxx.o), building for iOS simulator, but linking in object file built for OSX, for architecture x8(botched)
昨天遇到一个问题,在项目swift1.2适配swift2.0的过程中,修改完毕之后,运行报错如下: /Pods/NewRelicAgent/NewRelic_iOS_Agent_5.1.0/NewRe ...
- hibernate 超级牛x的公共类
想法,能支持in查询和 =查询的 公共方法,类似下面实现 用 泛型 实现 参数 getList(String[] params,Object[] values){} for(int i=0;i< ...
- 玩耍Hibernate系列(二)--基础知识
Hibernate思维导图 Hibernate映射 关于hibernate的映射要说明的一点就是关于ID的访问权限,peroperty以及field的区别: 表的主键在内存中对应一个OID对象描述 ...
- Java基础学习总结--Java对象的序列化和反序列化
一.序列化和反序列化的概念 把对象转换成字节序列的过程称之为对象的序列化 把字节序列恢复为对象的过程称之为对象的反序列化 对象序列化的主要用途: 1)把对象的字节序列永久的保存到硬盘上,通常放在一个文 ...
- ios应运程序的五种状态
ios应运程序的五种状态即转化 从apple的官方文档扣下来的 5状态: Not running The app has not been launched or was running but w ...
- Ionic入门一:Hello Ionic
1.在终端里面进入准备存放App的目录:  2.Ionic官网提供了三个项目模板blank.tabs和sideMenu ,用“ionic start myApp tabs”创建ionic项目:  ...