题意:给出一个矩阵,这个矩阵由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. nyoj--214--单调递增子序列(二)(二分查找+LIS)

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长子序 ...

  2. linux 挂载存储步骤(以emc 5300为例)

    挂载存储有两种方式:光纤模式(hub卡)和iscsi (以太网).两者大体思路是一样的. 1.在应用服务器上安装hub卡,连接光纤到光纤交换机上: 2.在应用服务器安装hub卡驱动程序: 3.在存储上 ...

  3. 4.git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案

    转自:https://zhiku8.com/git-could-not-read-from-remote-repository.html 我们在使用git clone 或其他命令的时候,有时候会遇到这 ...

  4. Windbg调试托管代码

    Windbg调试.net托管代码需要借助于SOS.dll,.Net 4.0的32位sos.dll的路径在C:\Windows\Microsoft.NET\Framework\v4.0.30319,64 ...

  5. c# 02-18 值类型 引用类型 字符串的不可变性 字符串的处理方法

    1值类型 直接把值存在栈中 栈的特点是后进先出 int double decimal char struct enum bool 2 引用类型 把值存在堆中,把地址存在栈中: string 自定义的类 ...

  6. 关于Scrapy爬虫项目运行和调试的小技巧(下篇)

    前几天给大家分享了关于Scrapy爬虫项目运行和调试的小技巧上篇,没来得及上车的小伙伴可以戳超链接看一下.今天小编继续沿着上篇的思路往下延伸,给大家分享更为实用的Scrapy项目调试技巧. 三.设置网 ...

  7. java 通过cookie判断是否登陆

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOEx ...

  8. layui层级

    zIndex:layer.zIndex, success : function(layero){ var zIndex = layer.index; $(layero).css(‘z-index’,z ...

  9. POJ-3436 ACM Computer Factory 最大流 为何拆点

    题目链接:https://cn.vjudge.net/problem/POJ-3436 题意 懒得翻,找了个题意. 流水线上有N台机器装电脑,电脑有P个部件,每台机器有三个参数,产量,输入规格,输出规 ...

  10. C语言Huffman压缩和解压

    符号表结构体: struct node { // 字符串形式存储的Huffman编码 char code[MAX_CODE_LENGTH]; // 这个字符在文件中出现的次数 long count; ...