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

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

翻译:mike搞了一台机器专门清洗中毒的奶酪,有一天,机器也中毒了并且开始自顾自的清洗奶酪,被中毒的机器清洗的奶酪也会中毒,mike即时发现了这个问题,修复机器后,想要以最少的操作数,让之前中毒的奶酪回复正常。
思路:如果一个操作带有‘*’,那么机器将会同时清理两个奶酪,那么在最后清理奶酪时,尽量使用带'*'号的操作可以更快的清理完奶酪,若我们建图,并且让中毒奶酪的编号相差1的奶酪连一条边,这些连边的两块奶酪使用‘*’操作来清理1次就行,这相当于找一个最大独立集,集合中每两块奶酪都没有连边,若把集合中的奶酪全部清理了,就相当于把所有中毒奶酪都清洗了;
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<bitset>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = ;
int V;//点的个数
vector<int>G[N_MAX];
int match[N_MAX];
bool used[N_MAX];
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
} bool dfs(int v) {
used[v] = true;
for (int i = ; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
} int bipartite_matching() {
int res = ;
memset(match, -, sizeof(match));
for (int v = ; v < V; v++) {
if (match[v] < ) {
memset(used, , sizeof(used));
if (dfs(v))
res++;
}
}
return res;
} int N, M;
string s[N_MAX];
vector<int>operation;
int main() {
while (scanf("%d%d",&N,&M)&&N) {
//operation.resize(N);
for (int i = ; i < M;i++)
cin >> s[i];
for (int i = ; i < M; i++) {
int x=;
for (int j = ; j < s[i].size();j++) {
if(s[i][j]=='')x += << (N - j - );
}
operation.push_back(x);
for (int j = ; j < s[i].size();j++) {
if (s[i][j] == '*')x += << (N - j - );
}
operation.push_back(x);
}
sort(operation.begin(),operation.end());
operation.erase(unique(operation.begin(),operation.end()),operation.end());
V = operation.size();
for (int i = ; i < V;i++) {
for (int j = i + ; j < V;j++) {
bitset<>bit = operation[i] ^ operation[j];//找找二进制有几位是一样的
if (bit.count() == ) {//只有一位是一样的,可以让机器使用'*'操作,符合连边条件
add_edge(i, j);
}
}
}
printf("%d\n",V-bipartite_matching());
for (int i = ; i < V;i++) {
G[i].clear();
}
operation.clear();
}
return ;
}

poj 2724 Purifying Machine的更多相关文章

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

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

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

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

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

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

  4. poj 2724 Purifying Machinef

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

  5. POJ 2724

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

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

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

  7. 【poj2724】 Purifying Machine

    http://poj.org/problem?id=2724 (题目链接) 题意 Mike有一个机器可以帮助他清理奶酪,每个奶酪由一个n位二进制数表示,机器上一共有n个按钮,每个按钮有1,0,*,其中 ...

  8. POJ 1276 Cash Machine -- 动态规划(背包问题)

    题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...

  9. POJ2724:Purifying Machine——题解

    http://poj.org/problem?id=2724 描述迈克是奶酪工厂的老板.他有2^N个奶酪,每个奶酪都有一个00 ... 0到11 ... 1的二进制数.为了防止他的奶酪免受病毒侵袭,他 ...

随机推荐

  1. Python——函数入门(二)

    一.函数的参数 我们在定义函数时,可以定义形式参数(简称形参),这些形参的值在函数调用的时候才会确定,形参的值由调用者负责传入. 1.关键字参数 在Python中,函数的参数名并不是没有意义的,在调用 ...

  2. 01_2_模拟spring装载bean

    01_2_模拟spring装载bean 1. xml配置文件内容 beans.xml <beans> <bean id="u" class="com.w ...

  3. wsl基本安装与配置

    wsl简介: Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层.它是由微软与Canoni ...

  4. 科技庄园(背包dp)---对于蒟蒻来说死了一大片的奇题

    题目描述: Life种了一块田,里面种了一些桃树. Life对PFT说:“我给你一定的时间去摘桃,你必须在规定的时间之内回到我面前,否则你摘的桃都要归我吃!” PFT思考了一会,最终答应了! 由于PF ...

  5. CentOS7下Mysql5.7主从数据库配置

    本文配置主从使用的操作系统是Centos7,数据库版本是mysql5.7. 准备好两台安装有mysql的机器(mysql安装教程链接) 主数据库配置 每个从数据库会使用一个MySQL账号来连接主数据库 ...

  6. 03等待多个线程返回WaitForMultipleObject

    二. WaitForMultipleObject 等待单个线程返回 1. 函数原型 DWORD WINAPI WaitForMultipleObjects( _In_ DWORD nCount, _I ...

  7. VUE2.0声明周期钩子:不同阶段不同钩子的开启

  8. nova虚拟机镜像从创建到文件系统resize完整流程

    1. 虚拟机镜像的创建和resize流程 nova创建虚拟机涉及的组件比较多,调用比较复杂,这里只列出跟虚拟机镜像创建相关的流程,方便理清虚拟机状态变化的整个流程. nova-api nova.api ...

  9. svn 命令管理

    有时候测试环境会让更新到指定版本,用以验证问题或者其他原因 具体方法有两种: 方法1: svn merge回滚 1) 先 svn up,保证更新到最新的版本,如2106: 2) 然后用 svn log ...

  10. Win7里IIS7部署WebService

    最近忙于一个Web的Bug修正,是先人写的一个东东,架构很简单,一个前端的项目,一个WebService的项目,以及后台的一些dll.之前一直很排斥这个产品,因为它没法启动,印象中没有跑得起来过的时候 ...