题目链接:https://vjudge.net/problem/HDU-1054

Strategic Game

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8673    Accepted Submission(s): 4174

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 description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
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.

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 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
Source
Southeastern Europe 2000

最小点覆盖:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<vector>
 4 using namespace std;
 5
 6 vector<int>G[1510];
 7 bool vis[1510];
 8 int match[1510];
 9
10 bool dfs(int u)
11 {
12     for(int i = 0; i<G[u].size(); i++)
13     {
14         int t = G[u][i];
15         if(!vis[t])
16         {
17             vis[t] = true;
18             if(match[t]==-1 || dfs(match[t]))
19             {
20                 match[t] = u;
21                 return true;
22             }
23         }
24     }
25     return false;
26 }
27
28 int main()
29 {
30     int n,m,k,a,ans;
31     while(scanf("%d",&n)==1)
32     {
33         for(int i = 0; i<n; i++)
34             G[i].clear();
35         for(int i = 0; i<n; i++)
36         {
37             scanf("%d:(%d)",&m,&k);
38             for(int j = 0; j<k; j++)
39             {
40                 scanf("%d",&a);
41                 G[m].push_back(a);
42                 G[a].push_back(m);
43             }
44         }
45
46         ans = 0;
47         memset(match,-1,sizeof(match));
48         for(int i = 0; i<n; i++)
49         {
50             memset(vis,false,sizeof(vis));
51             if(dfs(i))
52                 ans++;
53         }
54
55         printf("%d\n",ans/2);
56     }
57 }

View Code

树形DP:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5
 6 struct
 7 {
 8     int to, next;
 9 }e[1510];
10
11 int h[1510], dp[1510][2], num;
12
13 void addedge(int u, int v)
14 {
15     e[num].to = v;
16     e[num].next = h[u];
17     h[u] = num++;
18 }
19
20 int dfs(int u)
21 {
22     int v;
23     dp[u][0] = 0; dp[u][1] = 1;
24     for(int i = h[u]; i!=-1; i = e[i].next)
25     {
26         v = e[i].to;
27         dfs(v);
28         dp[u][0] += dp[v][1];
29         dp[u][1] += min(dp[v][0],dp[v][1]);
30     }
31     return min(dp[u][0], dp[u][1]);
32 }
33
34 int main()
35 {
36     int n,m,u,v,k,rt;
37     while(~scanf("%d",&n))
38     {
39         memset(h,-1,sizeof(h));
40         rt = -1; num = 0;
41         for(int i = 0; i<n; i++)
42         {
43             scanf("%d:(%d)",&u,&k);
44             for(int j = 0; j<k; j++)
45             {
46                 scanf("%d",&v);
47                 addedge(u,v);
48             }
49
50             if(rt==-1) rt = u;
51         }
52
53         printf("%d\n",dfs(rt));
54     }
55 }

View Code

转载于:https://www.cnblogs.com/DOLFAMINGO/p/7818382.html

HDU1054 Strategic Game —— 最小点覆盖 or 树形DP相关推荐

  1. 【POJ - 1463】Strategic game (树上最小点覆盖,树形dp)

    题干: Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the ...

  2. HDU 1054 Strategic Game 最小点覆盖

     最小点覆盖概念:选取最小的点数覆盖二分图中的所有边. 最小点覆盖 = 最大匹配数. 证明:首先假设我们求的最大匹配数为m,那么最小点覆盖必然 >= m,因为仅仅是这m条边就至少需要m个点.然后 ...

  3. HDU - 1054 Strategic Game(最小点覆盖-二分图最大匹配)

    题目链接:点击查看 题目大意:给出一棵树,现在要在节点上放置士兵,每个士兵可以监视与其所在的节点直接相连的节点,问最少需要多少个士兵才能将整棵树都监视到 题目分析:求最少的节点,以保证每条边都有一个端 ...

  4. hdu 1054 Strategic Game 最小点覆盖 = 最大二分匹配

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1054 简单二分匹配,根据题意构造一个无向图.然后求最小点覆盖,然后扫描mark数组将曾经匹配的点所匹配 ...

  5. 最小支配集,最小点覆盖,最大独立集(贪心/DP)

    最小支配集(minimal dominating set):对于图G=(V,E)来说,设V'是图G的一个支配集,则对于图中的任意一个顶点u,要么属于集合V',要么与V'中的顶点相连. 在V'中除去任何 ...

  6. 树形DP求树的最小支配集,最小点覆盖,最大独立集

    转自:https://www.cnblogs.com/Ash-ly/p/5783877.html 一:最小支配集 考虑最小支配集,每个点有两种状态,即属于支配集合或者不属于支配集合,其中不属于支配集合 ...

  7. Strategic game(树的最小点覆盖)

    Strategic game 题意: 一个树,在一个节点放兵,周围的边就被守护,守护所有的边,问最少放多少兵 题解: 这种问题又称树的最小点覆盖 dp[x][1]以x为根的子树全被看住且在x上放置士兵 ...

  8. [51nod1299]监狱逃离 树形DP || 20w个点的网络流最小割ORZ

    监狱有N条道路连接N + 1个交点,编号0至N,整个监狱被这些道路连在一起(任何2点之间都有道路),人们通过道路在交点之间走来走去.其中的一些交点只有一条路连接,这些点是监狱的出口.在各个交点中有M个 ...

  9. 1579: 【例 5】皇宫看守(最小支配集——贪心求解/树形DP)

    [题目描述] 太平王世子事件后,陆小凤成了皇上特聘的御前一品侍卫. 皇宫以午门为起点,直到后宫嫔妃们的寝宫,呈一棵树的形状,某些宫殿间可以互相望见.大内保卫森严,三步一岗,五步一哨,每个宫殿都要有人全 ...

  10. hdu 1054 Strategic Game 二分图最小点覆盖

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题意: 给出一个无向图,求最小点覆盖. 思路: 用网络流来做设立一个超级源点和一个超级汇点. 每 ...

最新文章

  1. MySQL 到底是怎么解决幻读的?
  2. 项目如何用jetty运行_阿里大牛教你如何用Dubbox+SpringBoot+Docker架构,实现双11项目...
  3. c#中的23种设计模式
  4. 【知乎摘要】女生婚前应该清楚男友哪些方面了才能嫁给他
  5. 支持林嘉文老师竞选IEEE Circuits and Systems Society Member-at-Large (BoG)
  6. 数据仓库etl编程_莱牛教育:浅谈大数据ETL大数据工程师所需具备的能力
  7. 结队编程1-四则运算(107、120)
  8. C#设计模式-单例模式
  9. 摩托罗拉投资Android社交游戏拓荒商Moblyng
  10. 【Retinex】【Frankle-McCann Retinex】matlab代码注释
  11. 如何通过数据驱动业务发展
  12. 白话isEqual和hash的关系
  13. 云原生KubeSphere DevOps流水线部署RuoyiCloud
  14. C4D学习笔记3-动画-动画渲染流程案例
  15. SEM代码篇----R详细实现(SEM 2)
  16. ov5640_mipi.c分析
  17. 「2019纪中集训Day23」解题报告
  18. 服务器系统都有哪些?
  19. NodeJs string与base64互转
  20. 为什么网络掩码一定是255.255.255.0(/24)

热门文章

  1. Illustrator 教程,如何在 Illustrator 中编辑路径和形状?
  2. 苹果mac图像后期处理软件:Lightroom Classic
  3. Xilisoft DVD to iPhone Converter使用教程
  4. recyclerview简单实现单选多选反选全选
  5. 统一对外的接口,支持requestBody以及表单提交的坑
  6. 常用Docker 镜像命令(二)
  7. spring-security 学习参考网站
  8. 如何让Activiti-Explorer使用sql server数据库
  9. ODAC(V9.5.15) 学习笔记(十六)直接访问模式
  10. Ajax学习笔记-JQuery中的Ajax