| Time Limit: 2000MS | Memory Limit: 10000K | |
| Total Submissions: 2096 | Accepted: 870 |
Description
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 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
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
题目描述了一个树形结构,在结点上可安放0个或1个士兵,
要求在满足每条边的两端至少有一个士兵的条件下求得士兵最少数
以1表示放置,0表示不放置,
d[u][1]表示节点u放置士兵情况下以u为节点子树的最优值,
同理d[u][0]表示不放置为最优值,
转移方程为:
for(v 属于 u的子节点) d[u][1] += max(d[v][0], d[v][1])
for(v 属于 u的子节点) d[u][0] += d[v][1]
1465



被折叠的 条评论
为什么被折叠?



