UVA 1292 十二 Strategic game
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std; vector <int> a[];
int dp[][],vis[]; void dfs(int o)
{
vis[o]=;dp[o][]=;dp[o][]=;
for(int i=;i<a[o].size();i++)
{
int v=a[o][i];
if(vis[v]==) continue;
dfs(v);
dp[o][]=dp[o][]+min(dp[v][],dp[v][]);
dp[o][]=dp[o][]+dp[v][];
}
return;
} int main()
{
int n,m,x,y;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<=n;i++)
a[i].clear();
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis));
while(n--)
{
scanf("%d:(%d)",&x,&m);
for(i=;i<=m;i++)
{
scanf("%d",&y);
a[x].push_back(y);
a[y].push_back(x);
}
} dfs();
printf("%d\n",min(dp[][],dp[][]));
}
return ;
}
UVA 1292 十二 Strategic game的更多相关文章
- 树形DP UVA 1292 Strategic game
题目传送门 /* 题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择 树形DP:dp[i][0/1]表示当前点选或不选,如果选,相邻的点可选可不选,取最小值 */ /***** ...
- uva 1292 树形dp
UVA 1292 - Strategic game 守卫城市,城市由n个点和n-1条边组成的树,要求在点上安排士兵,守卫与点相连的边.问最少要安排多少士兵. 典型的树形dp.每一个点有两个状态: dp ...
- 前端开发中SEO的十二条总结
一. 合理使用title, description, keywords二. 合理使用h1 - h6, h1标签的权重很高, 注意使用频率三. 列表代码使用ul, 重要文字使用strong标签四. 图片 ...
- CRL快速开发框架系列教程十二(MongoDB支持)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- 我的MYSQL学习心得(十二) 触发器
我的MYSQL学习心得(十二) 触发器 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数 ...
- Web 前端开发精华文章推荐(jQuery、HTML5、CSS3)【系列十二】
2012年12月12日,[<Web 前端开发人员和设计师必读文章>系列十二]和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HT ...
- 第十二章Fundamental Data Types 基本数据类型
目录: 12.1 数值概论 12.2整数 12.3浮点数 12.4 字符和字符串 12.5布尔变量 12.6枚举类型 12.7具名常量 12.8数组 12.9创建你自己的类型 12.1 数值概论 ...
- [分享] IT天空的二十二条军规
Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...
- Bootstrap <基础三十二>模态框(Modal)插件
模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 如果您想要单独引用该插件的功能,那么您需要引用 ...
随机推荐
- 针对Android 模拟器启动慢的问题
Android 模拟器一直以运行速度慢著称,可以使用intel HAXM技术为Andorid模拟器加速.使模拟器运行度媲美真机, 彻底解决模拟器运行慢的问题. 1. Intel HAXM 是什么 In ...
- java 网络编程(二)----UDP基础级的示例
下面介绍UDP基础级的代码示例: 首先了解创建UDP传输的发送端的思路: 1.创建UDP的Socket服务.2.将要发送的数据封装到数据包中.3.通过UDP的socket服务将数据包发送出去.4.关闭 ...
- [置顶] 关于产品的一些思考——腾讯之UIDesigner
首先要赞一下这个软件,上手快,效果好,不过还有些有待提高的地方. 1.不稳定 设置了页面跳转效果后,继续编辑,前边已经编辑过的页面跳转效果有的会失效,或者变为其他跳转效果. 2.键盘无 ...
- button改变背景与文字颜色
1.定义/zhsh/res/color/txt_guide_selector.xml <?xml version="1.0" encoding="utf-8&quo ...
- selenium启动PhantomJS错误
from selenium import webdriverbrowser = webdriver.PhantomJS(executable_path="D:\PhantomJS\phant ...
- 161021、spring异步调用,完美解决!
前言 项目中,用户抢单,下单需要向对方推送消息,但是加上推送就会造成抢单和下单性能降低,反应变慢,因为抢单下单动作跟推送部分是同步的,现在想改成异步推送. 在Java应用中,绝大多数情况下都是通过同步 ...
- 160901、在大型项目中组织CSS
编写CSS容易. 编写可维护的CSS难. 这句话你之前可能听过100次了. 原因是CSS中的一切都默认为全局的.如果你是一个C程序员你就知道全局变量不好.如果你是任何一种程序员,你都知道隔离和可组合的 ...
- SQL SERVER 2008 中三种分页方法与总结
建立表: CREATE TABLE [TestTable] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NULL , ) COLLATE Chinese_ ...
- html5 canvas 笔记四(变形 Transformations)
绘制复杂图形必不可少的方法 save() 保存 canvas 状态 restore() 恢复 canvas 状态 Canvas 的状态就是当前画面应用的所有样式和变形的一个快照. Canvas 的状态 ...
- Hibernate,JPA注解@DynamicInsert和@DynamicUpdate,Hibernate如何插入sysdate
@DynamicInsert属性:设置为true,设置为true,表示insert对象的时候,生成动态的insert语句,如果这个字段的值是null就不会加入到insert语句当中.默认false. ...