Strategic Game
Strategic Game |
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 141 Accepted Submission(s): 96 |
Problem Description
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. 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 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. For example for the tree: the solution is one soldier ( at the node 1). 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). An example is given in the following table: |
Sample Input
4 |
Sample Output
1 |
Source
Southeastern Europe 2000
|
Recommend
JGShining
|
/*
初步思想:树状DP+搜索 加一个标记现在这个节点放不放士兵\ 1A,哈哈哈哈
*/
#include<bits/stdc++.h>
#define N 1505
using namespace std;
vector<int>edge[N];
int n;
int u,m,v;
int dp[N][];//dp[i][1/0]表示以i为根节点放士兵和不放士兵的最小值
void dfs(int root,int fa){
dp[root][]=;
dp[root][]=;
for(int i=;i<edge[root].size();i++){
int v=edge[root][i];
if(v==fa) continue;
dfs(v,root);
dp[root][]+=dp[v][];
dp[root][]+=min(dp[v][],dp[v][]);
}
}
int main(){
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
memset(dp,,sizeof dp);
for(int i=;i<=n;i++)
edge[i].clear();
for(int i=;i<n;i++){
scanf("%d:(%d)",&u,&m);
for(int j=;j<m;j++){
scanf("%d",&v);
edge[u].push_back(v);
edge[v].push_back(u);
}
}//建图
// for(int i=0;i<n;i++){
// cout<<edge[i].size()<<endl;
// }
dfs(,-);
printf("%d\n",min(dp[][],dp[][]));
}
return ;
}
Strategic Game的更多相关文章
- HDU1054 Strategic Game——匈牙利算法
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...
- DDD:Strategic Domain Driven Design with Context Mapping
Introduction Many approaches to object oriented modeling tend not to scale well when the application ...
- poj 1463 Strategic game DP
题目地址:http://poj.org/problem?id=1463 题目: Strategic game Time Limit: 2000MS Memory Limit: 10000K Tot ...
- UVA 1292 十二 Strategic game
Strategic game Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- hdu---(1054)Strategic Game(最小覆盖边)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1054:Strategic Game
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ1463:Strategic game(树形DP)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- hdoj 1054 Strategic Game【匈牙利算法+最小顶点覆盖】
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Making the Elephant Dance: Strategic Enterprise Analysis
http://www.modernanalyst.com/Resources/Articles/tabid/115/ID/2934/categoryId/23/Making-the-Elephant- ...
- (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)
题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- Redis的安装以及在项目中使用Redis的一些总结和体会
第一部分:为什么我的项目中要使用Redis 我知道有些地方没说到位,希望大神们提出来,我会吸取教训,大家共同进步! 注册时邮件激活的部分使用Redis 发送邮件时使用Redis的消息队列,减轻网站压力 ...
- 判断字符串中是否包含指定的内容&&字符串截取方法比较说明
1.使用indexOf()方法 方法说明: 作用:indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置(从前向后查找). 语法:stringObject.indexOf(searc ...
- RMQ-ST算法的理解与实现(C++)
RMQ-ST的含义 RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返 ...
- OpenCV探索之路(二十五):制作简易的图像标注小工具
搞图像深度学习的童鞋一定碰过图像数据标注的东西,当我们训练网络时需要训练集数据,但在网上又没有找到自己想要的数据集,这时候就考虑自己制作自己的数据集了,这时就需要对图像进行标注.图像标注是件很枯燥又很 ...
- Query DSL(1)
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl.html Query DSL GET _search { & ...
- 关于 String 自我理解
String 的一些认识: String对象是不可变,所以使用 final 修饰 字符串拼接,合理利用 StringBuilder(线程非安全),StringBuffer 线程安全 常用方法就不详细介 ...
- 【Spring】高级装配
前言 前面讲解了bean的核心装配技术,其可应付很多中装配情况,但Spring提供了高级装配技术,以此实现更为高级的bean装配功能. 高级装配 配置profile bean 将所有不同bean定义放 ...
- apache一个ip多个端口虚拟主机
1.打开httpd.conf,查找Listen:80,在下面一行加入Listen:8080:2.查找#Include conf/extra/httpd-vhosts.conf,将此行前面的#去掉:3. ...
- Sublime Text保存文件时自动去掉行末空格
修改一个Sublime Text的用户配置,其中这个配置就是"保存文件时自动去掉每行结束后多余的空格",具体操作如下: 在Sublime Text菜单栏中找到preferences ...
- jdbc-日期格式的转换及代码示例
时间类型相互转换 把数据库的三种时间类型赋给java.util.Date,基本不用转换,因为这是把子类对象给父类的引用,不需要转换. java.sql.Date date = - java.ut ...