poj Purifying Machine 判定两个二进制串是否相差一位

Purifying Machine

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1
Problem Description
Mike is the owner of a cheese factory. He has 2N cheeses and each cheese is given a binary number from 00...0 to 11...1. To keep his cheese free from viruses, he made himself a purifying machine to clean virus-infected cheese. As a talented programmer, his purifying machine is built in a special way. His purifying machine has N switches, each switch has three states, 1, 0 and *. An operation of this machine is a cleaning action according to the states of the N switches. During one operation, at most one switch can be turned to state *, which can substitute for either 1 or 0. When the machine is turned to a specific state, an operation will clean all the cheeses with corresponding binary numbers. For example, if N equals 6 and the switches are turned to 01*100, the cheeses numbered 010100 and 011100 are under operation by the machine.
One day, Mike's machine was infected. When Mike found out, he had already done some operations and the cheeses operated by this infected machine were infected too. He cleaned his machine as quickly as he could, and now he needs to clean the infected cheeses with the minimum number of operations. If a cheese is infected, cleaning this cheese with the machine one or more times will make this cheese free from virus again; but if a cheese is not infected, operation on this cheese will make it go bad.
Now given the infected operations Mike has done, you need to find out the minimum number of operations that must be performed to clean all the infected cheeses without making any clean cheese go bad.
 
Input
There are several test cases. Each test case starts with a line containing two numbers N and M (1 <= N <= 10, 1 <= M <= 1000). N is the number of switches in the machine and M is the number of infected operations Mike has done. Each of the following M lines contains a switch state of the machine. A test case with N = M = 0 ends the input and should not be processed.
 
Output
For each test case, output one line containing an integer, which is the minimum number of operations Mike needs to do.
 
Sample Input
3 3 *01 100 011 0 0
 
Sample Output
2
 
Source
PKU
题目说是给出一些有二进制串确定的状态和一台机器,这个机器每一位共有三个状态,且'*'一次最多只能出现一次,如果两个状态只相差了一位,则表示这两个状态可以被同时操作,由于两个状态中1的个数同奇偶的时候不可能只差一位,所以按照1的个数的奇偶性来对点集划分成X,Y集合,如果两个状态相差一位,那么连边,这时候求出二分图的最大独立集就是答案
对于输入中的状态,可以奇数偶数各算一个,也可以奇数偶数都不算(此时输出最终结果时应当加上带星的状态的个数)。
posted @ 2012-05-02 21:49  lmnx  阅读(334)  评论(0编辑  收藏  举报