博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cell_phone_network(树形dp求最小支配集)
阅读量:4477 次
发布时间:2019-06-08

本文共 1170 字,大约阅读时间需要 3 分钟。

Cell Phone Network

 

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

51 35 24 33 5

Sample Output

2 这题就是个求最小点支配集的问题,之前用贪心解过,现在用dp解一下,具体过程看代码吧

转载于:https://www.cnblogs.com/bianjunting/p/11571983.html

你可能感兴趣的文章
django路由转发
查看>>
HBase环境搭建随笔
查看>>
SAX vs. DOM (Event vs. Tree)
查看>>
堆排序原理及算法实现(最大堆)
查看>>
批量梯度下降法(Batch Gradient Descent)
查看>>
说说无线路由器后门的那些事儿(1)-D-Link篇
查看>>
AJAX POST&跨域 解决方案 - CORS
查看>>
C#基础之接口
查看>>
三相交流电路中三相负载的计算方法
查看>>
Webform(Linq高级查、分页、组合查询)
查看>>
nio 序列化
查看>>
android:强大的图像下载和缓存库Picasso
查看>>
Tick and Tick------HDOJ杭州电(无法解释,直接看代码)
查看>>
開始Unity3D的学习之旅
查看>>
WEB安全实战(一)SQL盲注
查看>>
华为HG8347R V3R016C10S135光猫桥接 北京联通 恢复华为原版
查看>>
Java文件下载:如何编码文件名称以及如何设置HttpServletResponse
查看>>
python 之@staticmethod和@classmethod
查看>>
QQ通信机制(转)
查看>>
泛型高级通配符
查看>>