hdu National Treasures 二分图的最小点集覆盖

National Treasures
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 3
Problem Description
The great hall of the national museum has been robbed few times recently. Everyone is now worried about the security of the treasures on display. To help secure the hall, the museum contracted with a private security company to provide additional guards to stay in the great hall and keep an eye on the ancient artifacts. The museum would like to hire the minimum number of additional guards so that the great hall is secured.
The great hall is represented as a two dimensional grid of R × C cells. Some cells are already occupied with the museum’s guards. All remaining cells are occupied by artifacts of different types (statues, sculptures, . . . etc.) which can be replaced by new hired guards. For each artifact, few other cells in the hall are identified as critical points of the artifact depending on the artifact value, type of vault it is kept inside, and few other factors. In other words, if this artifact is going to stay in the hall then all of its critical points must have guards standing on them. A guard standing in a critical position of multiple artifacts can keep an eye on them all. A guard, however,
can not stand in a cell which contains an artifact (instead, you may remove the artifact to allow the guard to stay there). Also you can not remove an artifact and leave the space free (you can only replace an artifact with a new hired guard).
Surveying all the artifacts in the great hall you figured out that the critical points of any artifact (marked by a) are always a subset of the 12 neighboring cells as shown in the grid below.


Accordingly, the type of an artifact can be specified as a non-negative integer where the i-th bit is 1 only if critical point number i from the picture above is a critical point of that artifact. For example an artifact of type 595 (in binary 1001010011) can be pictured as shown in the figure below. Note that bits are numbered from right to left (the right-most bit is bit number 1.) If a critical point of an artifact lies outside the hall grid then it is considered secure.



You are given the layout of the great hall and are asked to find the minimum number of additional guards to hire such that all remaining artifacts are secured.


Input
Your program will be tested on one or more test cases. Each test case is specified using R+1 lines.
The first line specifies two integers (1<= R,C <= 50) which are the dimensions of the museum hall. The next R lines contain C integers separated by one or more spaces. The j-th integer of the i-th row is -1 if cell (i, j) already contains one of the museum’s guards, otherwise it contains an integer (0 <= T <= 212) representing the type of the artifact in that cell.
The last line of the input file has two zeros.


Output
For each test case, print the following line:
k. G
Where k is the test case number (starting at one,) and G is the minimum number of additional guards to hire such that all remaining artifacts are secured.


Sample Input
1 3
512 -1 2048
2 3
512 2560 2048
512 2560 2048
0 0


Sample Output
1. 0
2. 2

Hint

The picture below shows the solution of the second test case where the two artifacts in the middle are replaced by guards.



Source
2009 ANARC

题目说是每个文物都有一些关键点来设置守卫,如果某个文物A的关键点上有文物B存在,则可以将文物B移走后安置一个守卫(移走之后不能空者,并且要保留文物A ,则必须保证A的关键点上都有守卫存在),如果某个关键点已经有守卫了,则不需要新的守卫,问最少需要多少新守卫来看护这些文物。

考虑将50*50=2500个点的图,将文物和其对应的关键点连边(如果这个关点上已经有了一个守卫的话,则不需要连边),那么就是找最小的点覆盖所有的边,将每个点拆成两个点,作成二分图求最大匹配即可,另外考虑这个图的性质,将整个网格进行黑白染色,然后连边求最大匹配(在二分图中就等价与最小点覆盖)。

转载于:https://www.cnblogs.com/lmnx/archive/2012/04/30/2476847.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值