POJ 1463 Strategic game (树形dp 树的最小点覆盖 水)
来源:互联网 发布:开淘宝商城的条件 编辑:程序博客网 时间:2024/04/30 07:30
Strategic game
Time Limit: 2000MS Memory Limit: 10000KTotal Submissions: 7486 Accepted: 3481
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.
For example for the tree:
the solution is one soldier ( at the node 1).
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 contains several data sets in text format. Each data set represents a tree with the following description:
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500);the number_of_roads in each line of input will no more than 10. Every edge appears only once in the input data.
- 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);the number_of_roads in each line of input will no more than 10. 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). An example is given in the following:
Sample Input
40:(1) 11:(2) 2 32:(0)3:(0)53:(3) 1 4 21:(1) 02:(0)0:(0)4:(0)
Sample Output
12
Source
Southeastern Europe 2000
题目链接:http://poj.org/problem?id=1463
题目大意:求树的最小点覆盖
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int const MAX = 1505;int head[MAX], cnt;int dp[MAX][2];struct EDGE{ int to, next;}e[MAX * MAX / 2];void Add(int u, int v){ e[cnt].to = v; e[cnt].next = head[u]; head[u] = cnt ++;}void DFS(int u, int fa){ dp[u][1] = 1; dp[u][0] = 0; for(int i = head[u]; i != -1; i = e[i].next) { int v = e[i].to; if(v != fa) { DFS(v, u); dp[u][1] += min(dp[v][0], dp[v][1]); dp[u][0] += dp[v][1]; } }}int main(){ int n; while(scanf("%d", &n) != EOF) { cnt = 0; memset(head, -1, sizeof(head)); int u, num, v, rt; for(int i = 0; i < n; i++) { scanf("%d:(%d)", &u, &num); if(i == 0) rt = u; for(int j = 0; j < num; j++) { scanf("%d", &v); Add(u, v); Add(v, u); } } if(n == 1) { printf("1\n"); continue; } memset(dp, 0, sizeof(dp)); DFS(rt, -1); printf("%d\n", min(dp[rt][0], dp[rt][1])); }}
0 0
- POJ 1463 Strategic game (树形dp 树的最小点覆盖 水)
- POJ 1463 Strategic game 最小点覆盖,树形DP
- poj 1463 Strategic game(最小点覆盖树形DP)
- POJ 1463 Strategic game 最小点覆盖集(树形dp)
- POJ 1463 Strategic game (二分图最小覆盖点(匈牙利算法) 或 树形DP)
- POJ 1463 Strategic game (树形DP,放置点覆盖边)
- poj 1463 Strategic game 树的最小点覆盖
- poj 1463 Strategic game 树型dp,最小点集覆盖
- hdu 1054 Strategic Game 树形dp基础题,树的最小点覆盖
- POJ 1463 Strategic game(树形DP-树上的点集覆盖模型)
- Uva 1292 - Strategic game 树形dp 最小点覆盖
- hdu1054 Strategic Game(最小覆盖点-树形dp)
- UVA1292-----Strategic game-----树形DP解决树上的最小点覆盖问题
- poj 1463 Strategic game(树形dp,最小边覆盖集)
- HDU 1054 Strategic Game(二分图最小点覆盖 或者 树形DP)
- poj 1463 树形dp 最小点覆盖
- 树形DP专辑--POJ 1463 Strategic game
- poj 1463 Strategic game(树形DP)
- Android图形资源
- iOS问题: 此证书的签发者无效
- python模块系列之 - subprocess
- LinkedList
- kidd风的IOS日志之利用dispatch_once创建单例
- POJ 1463 Strategic game (树形dp 树的最小点覆盖 水)
- 上网原理
- JAVA学习20160225
- GIS+=地理信息+云计算技术——[网络公开课]云GIS解决方案及应用案例
- div永远垂直居中的方法
- 单利模式的三要素
- 一天一个算法练习之打印斐波拉契数列
- 【bzoj3308】九月的咖啡店 费用流
- 报错:Conversion to Dalvik format failed: Unable to execute dex: