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 ...
随机推荐
- myeclipse 8.5最新注册码(过期时间到2016年)
myeclipse 8.5最新注册码(过期时间到2016年) 这几天myeclipse弹出注册码过期,去网上一搜,要么已过期,要么就剩一两个月.倒腾了半天,自己申请了几个注册码,给大家分享一下 Sub ...
- Android 数独游戏 记录
Android图形编程基本概念 颜色对象 Color 类 int color = Color.bule //蓝色 int color = Color.argb(255,255,255,255); ...
- 线程局部变量ThreadLocal的原理及使用范围_1
线程局部变量ThreadLocal的原理及使用范围 使用原理 每个Thread中都有一个ThreadLocalMap成员, 该成员是ThreadLocal的内部类ThreadLocalMap类型.每使 ...
- leetcode:Longest Palindromic Substring(求最大的回文字符串)
Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...
- spring实例化bean的方式
1.使用类构造器实现实例化(bean的自身构造器) <bean id = "orderService" class="cn.itcast.OrderServiceB ...
- iOS app的webview注入JS遇到的坑
webview使用JSContext 向网页js注入时时机要选为网页加载完成后即放在 -(void)webViewDidFinishLoad:(UIWebView *)webView 方法 : -(v ...
- [POJ] #1006# Biorhythms : 最小公倍数/同余问题
一. 题目 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127263 Accepted: 403 ...
- [cocos2d-js]chipmunk例子(二)
; ; ; ; <<; var NOT_GRABABLE_MASK = ~GRABABLE_MASK_BIT; var MainLayer = cc.Layer.extend({ _bal ...
- ajax 模仿百度下拉
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 【125】固定IP的电脑配置无线路由
标题所提到的情况即为有些电脑是用静态IP上网的,与普通的宽带连接稍微有些不同,例如我的电脑的静态IP设置是这样的: 只有按照上面的设置才可以正常上网,因此在配置无线路由器的时候也要用到上面的内容,废话 ...