题意:给出一个矩阵,这个矩阵由n个数的二进制表示,p表示用p位二进制来表示的一个数 问最少用多少列就能将这n个数区分开

枚举子集,然后统计每一种子集用了多少列,维护一个最小值

b[i]==1代表的是选择了这一列

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int b[maxn],a[][];
int minn,n,p; void solve(){
for(int i=;i<n-;i++){
for(int j=i+;j<n;j++){
int flag=;
for(int k=;k<p;k++)
if(b[k]&&a[i][k]!=a[j][k]) flag=;//b[k]==1代表的是选择了这一列 if(flag==) return;
}
} int ans=;
for(int i=;i<p;i++)
if(b[i]) ans++; // printf("ans=%d\n",ans);
// printf("minn=%d\n",minn);
minn=min(minn,ans);
} void subset(int cur){
if(cur==p){
solve();
return;
}
b[cur]=;
subset(cur+);
b[cur]=;
subset(cur+);
} int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T;
cin>>T;
while(T--){
cin>>p>>n;
for(int i=;i<n;i++)
for(int j=;j<p;j++)
cin>>a[i][j]; minn=p;
subset();
printf("%d\n",minn);
}
return ;
}

自己做的时候题目都没有读懂----sad------------

加油加油--

UVa 11025 The broken pedometer【枚举子集】的更多相关文章

  1. UVA 11205 The broken pedometer(子集枚举)

    B - The broken pedometer Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  2. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

  3. UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. uva 1151(最小生成树,枚举子集)

    题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐,可以 ...

  5. UVa 11205 - The broken pedometer

    称号:给你p一个LED在同一个显示器组成n一个.显示每个显示器上的符号(LED的p长度01串) 问:用最少p几个比特位,您将能够这些区分n不同的符号.同样不能(其他位置上设置0处理) 分析:搜索.枚举 ...

  6. UVa Live 4794 - Sharing Chocolate 枚举子集substa = (s - 1) & substa,记忆化搜索 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  8. 紫书 例题 11-3 UVa 1151 (有边集的最小生成树+二进制枚举子集)

    标题指的边集是说这道题的套餐, 是由几条边构成的. 思路是先做一遍最小生成树排除边, 因为如果第一次做没有加入的边, 到后来新加入了很多权值为0的边,这些边肯定排在最前面,然后这条边的前面的那些边肯定 ...

  9. UVA - 1151 Buy or Build (买还是建)(并查集+二进制枚举子集)

    题意:平面上有n个点(1<=n<=1000),你的任务是让所有n个点连通.可以新建边,费用等于两端点欧几里德距离的平方.也可以购买套餐(套餐中的点全部连通).问最小费用. 分析: 1.先将 ...

随机推荐

  1. Default Document <defaultDocument> IIS中的默认页面

    https://docs.microsoft.com/en-us/iis/configuration/system.webserver/defaultdocument/index Default do ...

  2. java布局管理

    FlowLayout :组件在一行中按加入的先后顺序从左至右水平排列,排满后折行,每行中的组件都居中排列.BorderLayout:把容器空间划分为北.南.西.东.中五个区,每加入一个组件都应说明把这 ...

  3. 51nod 1785 数据流中的算法 (方差计算公式)

    1785 数据流中的算法 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题   51nod近日上线了用户满意度检测工具,使用高级人工智能算法,通过用户访问时间.鼠 ...

  4. AOJ GRL_1_C: All Pairs Shortest Path (Floyd-Warshall算法求任意两点间的最短路径)(Bellman-Ford算法判断负圈)

    题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C All Pairs Shortest Path Input ...

  5. AOJ GRL_1_B: Shortest Path - Single Source Shortest Path (Negative Edges) (Bellman-Frod算法求负圈和单源最短路径)

    题目链接: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B   Single Source Shortest Path ...

  6. POJ 2155 Matrix【 二维树状数组 】

    题意:给出两种操作,C是给出一个矩形的左上角和左下角的下标,把这个矩形里面的0变成1,1变成0,Q是询问某个点的值 看这篇论文讲得很清楚 http://wenku.baidu.com/view/1e5 ...

  7. 转义JavaScript特殊字符

    JavaScriptUtils.javaScriptEscape("%admin' or '1=1") //转义JavaScript特殊字符

  8. GUI 图形用户界面 [学习笔记]

    今晚返璞归真了一把, 系统了解了一下GUI的有关知识: GUI(Graphical User Interface) 图形用户界面 是指采用图形方式显示的计算机操作用户接口.与早期计算机使用的命令行界面 ...

  9. parted 4T磁盘

    parted /dev/vdg mklabel gpt mkpart primary ext4 0% 100%

  10. python学习笔记:第六天

    一.元组(通用格式a=(1,),结束后面加个逗号,不同与数组是中括号,只能是只读的,不能修改,是有序的): 列表之间可以嵌套(列表之间嵌套,嵌套元组,是有序的):a[b[1,2],c[3,4]],输出 ...