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. CodeForces 569A 第八次比赛 C题

    Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...

  2. ES6 入门系列 - let 和 const 命令

    let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = ; ; } a // ReferenceEr ...

  3. AppCan教你从零开始做开发

    经常收到类似这样的提问:新手开发APP,要怎么学?我有满屏幕的文档和视频,然而并没有什么卵用,因为我不知道该从哪看起……今天的主要内容是教大家,如何在AppCan移动平台创建应用,引擎插件选择.证书管 ...

  4. greenDao生成的实体类无法存放JsonArray的解决方法

    今天在解析Json数据的时候,发现我们用greenDao生成的实体类只能是基本数据类型,而我请求回来的json数据里面还包含了jsonArray. 下面是json的数据格式 "content ...

  5. Go原子计数

    通过原子计数可以在多线程情况下,对同一个数值进行加减操作,一般用于状态同步. 先看代码: package main import "fmt" import "time&q ...

  6. 53.转:深入浅出FPGA-14-ChipScope软件使用

    引言 索性再破例一下,成个系列也行. 内容组织 1.建立工程 2.插入及配置核 2.1运行Synthesize 2.2新建cdc文件 2.3 ILA核的配置 3. Implement and gene ...

  7. 26.68013 烧录方式 及iic生成

    硬件程序烧录 1)因为本产品要求将二进制代码和硬件PID/VID烧录在EEPROM,而不是使用CYPRESS推荐的在线下载方式,所以外部采用了8K的EEPROM.上电后68013A会将EEPROM中的 ...

  8. Python实现kMeans(k均值聚类)

    Python实现kMeans(k均值聚类) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=> ...

  9. Linux 删除mysql数据库失败的解决方法

    使用命令:drop database xxx:删除本数据库时却删除失败,系统提示出现了错误,错误代码为: ERROR 1010 (HY000): Error dropping database(can ...

  10. Log4J配置文件说明

    Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境 ...