[动态规划] 放置街灯 Uva 10859 - Placing Lampposts

英文题目:

As a part of the mission �Beautification of Dhaka City�, thegovernment has decided to replace all the old lampposts with new expensive ones.Since the new ones are quite expensive and the budget is not up to therequirement, the government has decided to buy the minimum number of lamppostsrequired to light the whole city.

Dhaka city can be modeled as an undirected graph with no cycles, multi-edges orloops. There are several roads and junctions. A lamppost can only be placed onjunctions. These lampposts can emit light in all the directions, and that means alamppost that is placed in a junction will light all the roads leading away fromit.

The �Dhaka City Corporation� has given you the road map of Dhaka city. You arehired to find the minimum number of lampposts that will be required to light thewhole city. These lampposts can then be placed on the required junctions toprovide the service. There could be many combinations of placing these lamppoststhat will cover all the roads. In that case, you have to place them insuch a way that the number of roads receiving light from two lampposts ismaximized.

Input

There will be several cases in the input file. The first lineof input will contain an integerT(T<=30) that will determine the numberof test cases. Each case will start with two integersN(N<=1000) andM( M<N) that will indicate the number of junctions and roads respectively.The junctions are numbered from0 toN-1. Each of the next Mlines will contain two integersa andb, which implies there is aroad from junctiona tob,
( 0<= a,b < N ) and a != b. There is a blank line separating twoconsecutive input sets.

Output

For each line of input, there will be one line of output. Eachoutput line will contain 3 integers, with one space separating two consecutive numbers.The first of these integers will indicate the minimum number of lampposts required to light the whole city. The second integer will be the number of roads that are receivinglights from two lampposts and the third integer will be the number of roads thatare receiving light from only one lamppost.

Sample Input

2
4 3
0 1
1 2
2 3

5 4
0 1
0 2
0 3
0 4

Sample Output

2 1 2
1 0 4

Problem Setter: Sohel Hafiz.
Special thanks to Per Austrin.

我的思路是:

先将每个灯周围的路存储 为 1 其他 路为 0  .  再算出任意几个灯点亮之后的补集, 被重复点亮的路记为2, 只点亮一次的记为1, 没有点亮的是0.

优化公式x=M*a+b,        a为 未点亮的灯的个数,  b为 标记为2 的路的个数  M为略微大于路总数的一个常数.

之后遍历所有子集即可.

代码与我上一篇文章类似.

posted on 2015-03-04 09:23 rex686568 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/Pomodori/p/4356949.html

[动态规划] 放置街灯 Uva 10859 - Placing Lampposts相关推荐

  1. UVA - 10859 Placing Lampposts 放置街灯

    Placing Lampposts 传送门:https://vjudge.net/problem/UVA-10859 题目大意:给你一片森林,要求你在一些节点上放上灯,一个点放灯能照亮与之相连的所有的 ...

  2. uva 10859 放置街灯--Placing Lampposts

    uva 10859 - Placing Lampposts(树形dp ###两个别人家的代码,没有注释看了很久 ###所以自己改写了一遍,附注释 https://blog.csdn.net/keshu ...

  3. 10_放置街灯(Placing Lampposts,UVa 10859)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P70 例题30: 问题描述:有给你一个n个点m条边(m<n<=1000)的无向无环图,在尽量少的节点上放灯,使得所有边都被照 ...

  4. uva 10859 放置街灯树形dp

    首先,本题的优化目标有两个:放置的街灯a应该尽量少:被两灯同时照亮的边数b应该尽量大.为了统一起见,我们把后者替换为:恰好被一盏灯照亮的边数c应该尽量小,然后改用x = Ma+c作为优化目标,其中一个 ...

  5. UVA10859 放置街灯 Placing Lampposts(树状DP)

    UVA10859 放置街灯 Placing Lampposts(树状DP) 这道题有两种解决方法,因为原图保证无重边无环无自环, 所以原图一定是一颗树(或森林).,都是树状DP,但是实现的过程大同小异 ...

  6. Placing Lampposts ,UVa 10859 树形dp

    UVa 10859 日常刷白书,第三次刷dp刷到这题,竟然还是不会写..... 这个题给定n个点m条边的无向无环图,有至多1000个节点,每个节点有两个状态,可以放灯或者不放灯,要求放最少的灯使得所有 ...

  7. uva10859放置街灯(树形dp)

    例题 30 放置街灯( Placing Lampposts, UVa 10859 ) 给你一个 n 个点 m 条边的无向无环图, 在尽量少的结点上放灯, 使得 所有边都被照亮. 每盏灯将照亮以它为一个 ...

  8. Placing Lampposts UVA - 10859 放置街灯 树形dp

    As a part of the mission 'Beautification of Dhaka City', the government has decided to replace all t ...

  9. 树形DP(放置街灯,uva 10859)

    前面也做了一道很像的题,那道题只要求放置的数目最少,要求覆盖的是点.在这题中,要求覆盖的是边,不但要求放着的数目最少,更要求覆盖两次的边最多.因此贪心法不再适用,最少要多少个点可以贪心求出,但是同时要 ...

最新文章

  1. 技术直播:程序员副业的修炼指南!(限免报名)
  2. android学习之旅_01
  3. python数据怎么用不了_为什么自学Python看不进去?
  4. cordova降低版本10.0.0为8.1.2
  5. 【转】匈牙利算法理解
  6. 用标准C语言初始化线性表,C语言数据结构-顺序线性表的实现-初始化、销毁、长度、查找、前驱、后继、插入、删除、显示操作...
  7. vue父子组件传值之异步之后子组件无法拿到父组件传的值
  8. abview查找范例时说 NI服务器未定位 这是怎么回事?
  9. [旧文新读] 深度学习在Airbnb搜索的应用实践
  10. 自动生成html_服务搭建篇二·Jenkins+Jmeter+Gitlab持续集成实现接口流程自动化
  11. Apache+tomcat集群
  12. 详解回调函数(同步回调,异步回调)
  13. python 整合同类数据求分位值_【利用python进行数据分析】数据聚合与分组运算...
  14. 2020-11-01
  15. 课室用的电子黑板|一体手写屏哪家做的好?
  16. django-haystack 对 多对多字段( ManyToManyField )进行索引
  17. 四川省科学技术奖申报条件和18市补助
  18. linux下的清屏方法
  19. 【数据库】用户管理---君权神授
  20. 痛惜!年仅43岁,又一位985高校博导因病逝世

热门文章

  1. H5+微信公众号扫二维码页面跳转功能 vue实现
  2. 如何“快准狠”的找到内存的问题
  3. docker:error pulling image configuration
  4. 网络安全课程笔记(1)
  5. 如何把Windows10打造成Mac
  6. 为什么有的人赚钱很简单,有的人却不行?
  7. keras训练过程中发生的一些报错及其解决办法
  8. MSP430 单片机 SHT30 SHT31 温湿度传感器 MSP430F5529 MSP430G2553 程序
  9. analy32.xll下载_Android Studio 4.0添加了Motion Editor和Build Analyzer
  10. PDF拆分与合并工具(DOS版)