UVa11205 The Broken Pedometer
// 题意:有P个LED灯,以及N个字符,要求选出个数最少的LED灯,使得即使只有这些灯正常工作,也能区分出这N个字符
// 题意抽象:输入两个整数P, N以及N行P列的01矩阵,找少的列,能区分所有行
// 规模:P<=15, N<=100
// 算法:2^P枚举。把每行理解为二进制整数可以简化代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std; const int P=15;
const int N=100;
int p,n;
//bits
int buf[N]; set<int> s; bool judge(int x)
{
s.clear();
for(int i=0;i<n;i++)
{
int k=x & buf[i];
if(s.find(k)!=s.end())
{
return false;
}
s.insert(k);
}
return true;
} int count_bits(int x)
{
int cnt=0;
for(int i=0;i<p;i++)
{
if(x&(1<<i))
cnt++;
}
return cnt;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("./uva11205.in", "r", stdin);
#endif
int T;
scanf("%d", &T);
while(T--)
{
memset(buf, 0, sizeof buf);
scanf("%d %d", &p, &n);
for(int i=0;i<n;i++)
for(int j=0;j<p;j++)
{
int b;
scanf("%d", &b);
buf[i]|=(b<<j);
} int ans=P;
for(int i=0;i<(1<<p);i++)
{
if(judge(i))
{
int t=count_bits(i);
if(t<ans)
ans=t;
}
}
printf("%d\n", ans);
} return 0;
}
UVa11205 The Broken Pedometer的更多相关文章
- uva11205 The broken pedometer 子集生成
PS:此题我在网上找了很久的题解,发现前面好多题解的都是没有指导意义的.后来终于找到了一篇好的题解. 好的题解的链接:http://blog.csdn.net/u013382399/article/d ...
- UVA 11205 The broken pedometer(子集枚举)
B - The broken pedometer Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- uva11025 The broken pedometer
6741870 ksq2013 UVA 11205 Accepted 60 C++11 5.3.0 1002 2016-08-04 14:25:22 题目大意如下:给定n个LED灯串,每个灯串由p ...
- UVa 11205 - The broken pedometer
称号:给你p一个LED在同一个显示器组成n一个.显示每个显示器上的符号(LED的p长度01串) 问:用最少p几个比特位,您将能够这些区分n不同的符号.同样不能(其他位置上设置0处理) 分析:搜索.枚举 ...
- UVa 11025 The broken pedometer【枚举子集】
题意:给出一个矩阵,这个矩阵由n个数的二进制表示,p表示用p位二进制来表示的一个数 问最少用多少列就能将这n个数区分开 枚举子集,然后统计每一种子集用了多少列,维护一个最小值 b[i]==1代表的是选 ...
- The broken pedometer-纯暴力枚举
The broken pedometer Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu i ...
- 备战NOIP每周写题记录(一)···不间断更新
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- TNS-12518 & Linux Error:32:Broken pipe
最近一周,有一台ORACLE数据库服务器的监听服务在凌晨2点过几分的时间点突然崩溃,以前从没有出现过此类情况,但是最近一周出现了两次这种情况,检查时发现了如下一些信息: $ lsnrctl servi ...
随机推荐
- android 中如何获取camera当前状态
/** * 测试当前摄像头能否被使用 * * @return */ public static boolean isCameraCanUse() { boolean canUse = true; Ca ...
- linux 下查看系统内存使用情况的方法
在Windows系统中查看内存的使用情况很简单,想必大家都已经耳熟能详了,那么在linux系统如何查看内存使用情况呢?下面和大家分享在Linux 下查看内存使用情况的free命令: [root@scs ...
- ubuntu 安装AMP环境的笔记 Prefork方式与fast-cgi方法
具体步骤如下: 系统:ubuntu 8.04 的发行版本 AMP with Prefork(mod-php5) 一.安装APACHE2 # sudo apt-get install ...
- PyPI镜像网站
镜像列表:http://www.pypi-mirrors.org/ 清华镜像:http://e.pypi.python.org/
- MapReduce 中job.setJarByClass()方法的疑惑
在调试mr实例的时候,遇到如下的情况,如图所示 说明:就是我的mr程序类名称和我设置的setJarByclass()中设置的不一样,但是程序竟然没有报错!!!!当时把我吓尿了 疑惑:如果这样设置的话, ...
- nagios监控linux设置
本章主要用来设置nagios的相关配置文件,从而能实现对linux系统的监控. 在进行监控相关服务的时候,nagios会周期性的调用插件去监测服务器的状态,nagios自带的所有插件都放在如下目录: ...
- Mac OS10.9 下python开发环境(eclipse)以及自然语言包NLTK的安装与注意
折腾了大半天,终于把mbp上python自然语言开发环境搭建好了. 第一步,安装JDK1.7 for mac MacOS10.9是自带python2.7.5的,够用,具体的可以打开终端输入python ...
- 通过xshell 设置代理上网
前言: 前段时间,选修了一门并行计算,老师给我们每个人分配了一个linux登录账号,通过这个账号,可能登录学校的一台linux . 一次偶然的机会,了解到可以通过xshell , ssh服务器给本地开 ...
- 【一段日子荟萃】where should I go.
当<UNIX环境高级编程>和<鸟哥的私房菜>到我的桌头的时候,我忽然产生了厌倦的心. NO,我不是想做这个,我不是想学习这个操作系统的结构和接口. 我想些一个操作系统,更一般的 ...
- debug 64bit dump of a 32bit process in windows 7 64bit
In Windows 7 the TaskMgr provides one easy way to create dump for the applications. You can right cl ...