UVa 11025 The broken pedometer【枚举子集】
题意:给出一个矩阵,这个矩阵由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【枚举子集】的更多相关文章
- UVA 11205 The broken pedometer(子集枚举)
B - The broken pedometer Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
- 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 ...
- uva 1151(最小生成树,枚举子集)
题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此,你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐,可以 ...
- UVa 11205 - The broken pedometer
称号:给你p一个LED在同一个显示器组成n一个.显示每个显示器上的符号(LED的p长度01串) 问:用最少p几个比特位,您将能够这些区分n不同的符号.同样不能(其他位置上设置0处理) 分析:搜索.枚举 ...
- 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 ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- 紫书 例题 11-3 UVa 1151 (有边集的最小生成树+二进制枚举子集)
标题指的边集是说这道题的套餐, 是由几条边构成的. 思路是先做一遍最小生成树排除边, 因为如果第一次做没有加入的边, 到后来新加入了很多权值为0的边,这些边肯定排在最前面,然后这条边的前面的那些边肯定 ...
- UVA - 1151 Buy or Build (买还是建)(并查集+二进制枚举子集)
题意:平面上有n个点(1<=n<=1000),你的任务是让所有n个点连通.可以新建边,费用等于两端点欧几里德距离的平方.也可以购买套餐(套餐中的点全部连通).问最小费用. 分析: 1.先将 ...
随机推荐
- LeetCode -- 求字符串数组中的最长公共前缀
题目描写叙述: Write a function to find the longest common prefix string amongst an array of strings.就是给定1个 ...
- 9.variant move function change_cast
包含的头文件 #include <iostream> #include <string> #include <boost/array.hpp> //异构的容器 #i ...
- WPF学习(二) - 绑定
绑定,这个看起来很神奇的东西,于我这种喜欢刨根儿的人而言,理解起来非常困难. WPF绑定的核心思想是:数据层属性值的改变,能反应给展示层,反之亦然,并且这个响应的过程能被分离出来. 传统Winf ...
- python中index、slice与slice assignment用法
python中index.slice与slice assignment用法 一.index与slice的定义: index用于枚举list中的元素(Indexes enumerate the elem ...
- 根据SPID查找SQL语句
SELECT /*+ ORDERED */ sql_text FROM v$sqltext a WHERE (a.hash_value, a.address) ...
- ActiveMQ学习笔记(9)----ActiveMQ静态网络连接
1. 启动多个Broker 在win10下同一台服务器启动多个Broker, 步骤如下: 1. 复制安装目录下的conf文件夹命名为conf2 2. 修改activemq.xml中的brokerNam ...
- SpringBoot学习笔记(15)----SpringBoot使用Druid
直接访问Druid官网wiki,有详细教程,地址如下: SpringBoot支持Druid地址:https://github.com/alibaba/druid/tree/master/druid-s ...
- 安卓、safari和微信各个浏览器的设计标准
- (转)Hadoop Eclipse开发环境搭建
来源:http://www.cnblogs.com/justinzhang/p/4261851.html This document is from my evernote, when I was s ...
- 51nod 1321 收集点心(最小割)
给出一种最小割的方法. 设\(num1[i]\),\(num2[i]\)为第i种形状的点心的两种口味的数量 设\(type[i]\),\(type[i]\)为第i种形状的点心的两种口味 假设\(num ...