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. CA证书过期

    CA证书问题请教!最近在客户这里做Exchange2010及RMS项目,对当前Ca证书颁发机构的环境做了下勘察和调研,发现有些地方出现警号显示过期,不知道会不会影响Exchange和Adrms的集成部 ...

  2. 【转】C#中Invoke的用法

    在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...

  3. Java Collections Source Code Series 1 --- 简介

    废话开篇 由于项目需要,需要对Java Collections进行系统地了解,所以在此记录下,方便自己,服务他人. Java Collections 简介 Java Collections 框架主要包 ...

  4. 使用angular封装echarts

    Echarts是一个开源的图表组件,图表比较丰富,工作中需要用到它来搭建一个数据展示系统.但是系统原有的框架是基于angular的,而echarts是基于原生js的,如果直接使用的话就丢失了angul ...

  5. Effective Objective-C 2.0之Note.03(属性详解)

    用Objective-C等面向对象语言编程时,“对象”(object)就是“基本构造单元”(building block),开发者可以通过对象来存储并传递数据.在对象之间传递数据并执行任务的过程就叫做 ...

  6. Win7下的本地网站发布

    今天闲来无事研究了一下网站的发布,之前一直以为很难的样子,当真正实现了就觉得他也不过如此,现在来把我的研究结果分享一下,如果有问题望大家提出来! 首先发布网站我们要在本地的电脑上安装IIS,这个就不多 ...

  7. 不再让内容把td撑开

    <style type="text/css"> table {width:600px;table-layout:fixed;} td {white-space:nowr ...

  8. Lua利用cjson读写json示例分享

    本文结合本人的实际使用经验和代码示例,介绍如何在Lua中对json进行encode和decode,需要的朋友可以参考下 我这里采用的是Lua CJson库,是一个高性能的JSON解析器和编码器,其性能 ...

  9. 如何解决读取到文件末尾时碰到EOF导致的重复输出或者无用输出

    当读取到文件末尾时,会碰到EOF,如何解决呢?    方法一:我们可以通过(ch=fin.get())!=EOF来结束读取,这样就不会像eof()那样碰到EOF之后,还会再进行一次读取,导致输出一个无 ...

  10. 软件工程随堂作业--随机产生30到四则运算(c语言)

    #include "stdio.h" #include "math.h" #include "stdlib.h" #include" ...