POJ3659 Cell Phone Network

POJ3659 Cell Phone Network
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3782 Accepted: 1305

Description

Farmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone towers on his N (1 ≤N ≤ 10,000) pastures (conveniently numbered 1..N) so they can all communicate.

Exactly N-1 pairs of pastures are adjacent, and for any two pastures A and B (1 ≤ A ≤ N; 1 ≤ B ≤ NA ≠ B) there is a sequence of adjacent pastures such that is the first pasture in the sequence and B is the last. Farmer John can only place cell phone towers in the pastures, and each tower has enough range to provide service to the pasture it is on and all pastures adjacent to the pasture with the cell tower.

Help him determine the minimum number of towers he must install to provide cell phone service to each pasture.

Input

* Line 1: A single integer: N
* Lines 2..N: Each line specifies a pair of adjacent pastures with two space-separated integers: A and B

Output

* Line 1: A single integer indicating the minimum number of towers to install

Sample Input

5
1 3
5 2
4 3
3 5

Sample Output

2

Source

*********************************************************************
题目大意:给定一棵树,求最小支配集。就是说用最少的点覆盖这棵树所有的边。
解题思路:发现,我的想法有点奇葩,和大家的一般思路不太一样。我对每个点设立了三种状态:0表示这个点没有覆盖正期待着被父亲节点覆盖,1表示在当前节点就是属于支配集,2表示当前节点被他的儿子覆盖。
状态转移:    dp[root][0]=sum{dp[son][2]};
      dp[root][1]=sum{min{dp[son][0],dp[son][1],dp[son][2]}};
      dp[root][2]=sum{min{dp[son][1],dp[son][2]}};这一条比较特殊,当括号内取小的时候如果一直取的是dp[son][2],就需要特殊处理,就是说必须有一个点是dp[son][1]的取值。还有就是这个方法的边界处理比较麻烦。

  

posted on   Fatedayt  阅读(325)  评论(0编辑  收藏  举报

编辑推荐:
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
阅读排行:
· 从零开始开发一个 MCP Server!
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档

导航

< 2011年9月 >
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 1
2 3 4 5 6 7 8

统计

点击右上角即可分享
微信分享提示