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 ...
随机推荐
- css3新属性的学习使用
display 可选值:none隐藏元素: block显示为块级元素: inline显示为行级元素 inlineblock显示为内联块级元素,本身将是一个行级元素,但是拥有 块级元素的所有属性,比如宽 ...
- PHPFastCGI进程管理器PHP-FPM详解
PHP-FPM是一个PHPFastCGI进程管理器,是只用于PHP的. PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中.必须将它patch到你的PH ...
- C#ZIP根据路径读取压缩包内文件数量
/// <summary> /// 根据压缩包路径读取此压缩包内文件个数 /// </summary> /// <param name="strAimPath& ...
- #define WIN32_LEAN_AND_MEAN
不加载MFC所需的模块.用英语解释:Say no to MFC如果你的工程不使用MFC,就加上这句,这样一来在编译链接时,包括最后生成的一些供调试用的模块时,速度更快,容量更小.不过对于较大工程,MF ...
- Java数据结构和算法总结-数组、二分查找
前言:在平时开发中数组几乎是最基本也是最常用的数据类型,相比链表.二叉树等又简单很多,所以在学习数据和算法时用数组来作为一个起点再合适不过了.本篇博文的所有代码已上传 github ,对应工程的 ar ...
- 化繁为简 经典的汉诺塔递归问题 in Java
问题描述 在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度教的主神梵天在创造世界的时候,在其中一根针上从下到上地穿好了由大到小的64片金片,这就是所谓的汉诺塔.不论白天黑 ...
- libsvn_subr-1.so.0: undefined symbol: apr_atomic_xchgptr 故障解决
源码编译安装完成之后,查看svn的安装版本会报以下错误 svn: symbol lookup error: /usr/local/subversion/lib/libsvn_subr-.so.: un ...
- HDU 1219 AC Me
strlen能不用就不用 #include<cstdio> #include<cstdlib> #include<iostream> #include<alg ...
- 从字符串获得MAC地址的方法
今日有感于编程水平下降,特意练习一下,根据MAC地址字符串,获取MAC地址的2种方法. #include <stdio.h> void func1(char *str){ unsigned ...
- iOS四种多线程(swift和oc)
在这篇文章中,我将为你整理一下 iOS 开发中几种多线程方案,以及其使用方法和注意事项.当然也会给出几种多线程的案例,在实际使用中感受它们的区别.还有一点需要说明的是,这篇文章将会使用 Swift 和 ...
