Purifying Machine
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4014   Accepted: 1127

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

 
找出所有被感染的元素,然后对两个元素满足二进制位有且仅有一个不相同的建一条边,不难证明此图是二分图,每多一条匹配边可以减少一次操作,求出最大匹配减掉即可
 
 #include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; #define maxn 2005 int n,m,len,ans;
int ele[maxn],match[maxn];
vector<int> G[maxn];
bool vis[maxn]; bool judge(int x1,int x2) {
int sum = ;
for(int i = ; i < ; ++i) {
if((x1 >> i & ) ^ (x2 >> i & )) ++sum;
} return sum == ;
}
void build() {
for(int i = ; i < len; ++i) {
for(int j = i + ; j < len; ++j) {
if(judge(ele[i],ele[j])) {
G[i].push_back(j);
G[j].push_back(i);
}
}
} } bool dfs(int u) {
for(int i = ; i < G[u].size(); ++i ) {
int v = G[u][i];
if(vis[v]) continue;
vis[v] = ;
if(match[v] == - || dfs(match[v])) {
match[v] = u;
return true;
}
} return false;
} void solve() { for(int i = ; i < len; ++i) G[i].clear();
build(); for(int i = ; i < len; ++i) {
match[i] = -;
} for(int i = ; i < len; ++i) {
memset(vis,,sizeof(vis));
if(dfs(i)) ++ans;
}
} int main()
{
// freopen("sw.in","r",stdin);
while(~scanf("%d%d",&n,&m)) {
len = ;
ans = ;
if(!n && !m) break;
char ch[];
for(int i = ; i < m; ++i) {
scanf("%s",ch);
int pos = -,sum = ;
for(int j = ; j < n; ++j) {
if(ch[j] == '')
sum += ( << (n - j - ));
if(ch[j] == '*')
pos = n - j - ;
} ele[len++] = sum;
if(pos != -) ele[len++] = sum + ( << pos); } sort(ele,ele + len);
len = unique(ele,ele + len) - ele; solve(); printf("%d\n",len - (ans / ));
} return ;
}

POJ 2724的更多相关文章

  1. poj 2724 Purifying Machinef

    poj 2724 Purifying Machinef 题意 每一个01串中最多含有一个'*','*'既可表示0也可表示1,给出一些等长的这样的01串,问最少能用多少个这样的串表示出这些串.如:000 ...

  2. POJ 2724 Purifying Machine(最大独立集)

    POJ 2724 Purifying Machine 题目链接 题意:这题题意有点没看懂.看了别人的题解, 给出m串长度为n的01串. 有些串中可能包括,这种串能够表示两个串,为1 和为0. 反复的算 ...

  3. POJ 2724 Purifying Machine (二分图匹配)

    题意 给定m个长度为n的01串(*既表示0 or 1.如*01表示001和101).现在要把这些串都删除掉,删除的方法是:①一次删除任意指定的一个:②如果有两个串仅有一个字符不同,则可以同时删除这两个 ...

  4. poj 2724 二分图最大匹配

    题意: 会给出M个串,我们要做的就是将这M个串给清除了.对于任意两个串,若二进制形式只有一位不一样,那么这两个串可以在一次操作消除,否则每个操作只能消除一个串. 3 3 *01 100 011 可以代 ...

  5. poj 2724 Purifying Machine

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5408   Accepted: 1575 ...

  6. TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 ...

  7. poj 2724 Purifying Machine(二分图最大匹配)

    题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...

  8. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  9. 图论常用算法之一 POJ图论题集【转载】

    POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...

随机推荐

  1. ADOMD连接SSAS和Mondrian,rex的终结者

    前传 公司使用Mondrian作为OLAP服务器,于是,不得不适用Java开源的Rex进行客户端连接,用了一段时间,实在无法忍受rex的笨拙,于是乎,一直希望有一个工具能够连接替代它. 周末闲来无事, ...

  2. 关于使用 Connect-Busboy 实现文件上传 优化说明

    这篇博文完全上关于上一篇的优化 先看上一篇 node.js 在 Express4.0 框架使用 Connect-Busboy 实现文件上传 因为从上次博客改用 connect-busboy 来上传文件 ...

  3. hdu 2425 Hiking Trip

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...

  4. 使用 Bumblebee 控制 NVIDIA 双显卡

    简介 Nvidia的双显卡切换技术叫Optimus(擎天柱),可惜只能在win7.vista下实现.Linux下没有对应的技术,当然苹果也没有.这导致独立显卡一直在启用,显卡发热升温,风扇狂转,却没有 ...

  5. 6.Inout双向端口信号处理方法

    Verilog中inout端口的使用方法 (本文中所有Verilog描述仅为展示inout端口的用法,实际描述则需要更丰富的功能描述) Inout端口的使用 在芯片中为了管脚复用,很多管脚都是双向的, ...

  6. eclipse插件开发中全局对象的获取

    转自:http://blog.csdn.net/liaomin416100569/article/details/7165425 1.获取系统默认的ShellShell shell = Platfor ...

  7. sqlite与C++进行连接

    SQLite数据库是零配置的,sqlite数据库不同于SqlServer等数据库,SQLite不需要复杂配置,只需要,将SQLite的库文件和动态链接文件拷贝到相应工程目录下,就可以使用SQLite数 ...

  8. JAVA栈实例—括号匹配

    import java.util.Stack; public class test { public static void main(String[] args){ System.out.print ...

  9. C++中常见的几种异常类型

    1.C++具有完善的异常捕获机制,采用try{}  catch(){}机制,这是C语言无法比拟的 2.常见的几种异常: bad_alloc:       请求分配内存失败, operator new ...

  10. php 设计API之优化 记

    服务器端 可以考虑使用rest实现,清晰url:put http://aa.com/news 客户端 curl实现muliti机制,实现多线程并发,节省多接口调用的时间 curl实现keepalive ...