UVA 11205 The broken pedometer(子集枚举)

B - The broken pedometer

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Appoint description: 
System Crawler  (2014-05-18)

Description

 The Broken Pedometer 

The Problem

A marathon runner uses a pedometer with which he is having problems. In the pedometer the symbols are represented by seven segments (or LEDs):

But the pedometer does not work properly (possibly the sweat affected the batteries) and only some of the LEDs are active. The runner wants to know if all the possible symbols:

can be correctly identified. For example, when the active LEDs are:

numbers 2 and 3 are seen as:

so they cannot be distinguished. But when the active LEDs are:

the numbers are seen as:

and all of them have a different representation.

Because the runner teaches algorithms at University, and he has some hours to think while he is running, he has thought up a programming problem which generalizes the problem of his sweat pedometer. The problem consists of obtaining the minimum number of active
LEDs necessary to identify each one of the symbols, given a number P of LEDs, and N symbols to be represented with these LEDs (along with the codification of each symbol).

For example, in the previous sample P = 7 and N = 10. Supposing the LEDs are numbered as:

The codification of the symbols is: "0" = 1 1 1 0 1 1 1; "1" = 0 0 1 0 0 1 0; "2" = 1 0 1 1 1 0 1; "3" = 1 0 1 1 0 1 1; "4" = 0 1 1 1 0 1 0; "5" = 1 1 0 1 0 1 1; "6" = 1 1 0 1 1 1 1;
"7" = 1 0 1 0 0 1 1; "8" = 1 1 1 1 1 1 1; "9" = 1 1 1 1 0 1 1. In this case, LEDs 5 and 6 can be suppressed without losing information, so the solution is 5.

The Input

The input file consists of a first line with the number of problems to solve. Each problem consists of a first line with the number of LEDs (P), a second line with the number
of symbols (N), and N lines each one with the codification of a symbol. For each symbol, the codification is a succession of 0s and 1s, with a space between them. A 1 means the corresponding LED is part of the codification of the symbol.
The maximum value of P is 15 and the maximum value of N is 100. All the symbols have different codifications.

The Output

The output will consist of a line for each problem, with the minimum number of active LEDs necessary to identify all the given symbols.

Sample Input

2
7
10
1 1 1 0 1 1 1
0 0 1 0 0 1 0
1 0 1 1 1 0 1
1 0 1 1 0 1 1
0 1 1 1 0 1 0
1 1 0 1 0 1 1
1 1 0 1 1 1 1
1 0 1 0 0 1 0
1 1 1 1 1 1 1
1 1 1 1 0 1 1
6
10
0 1 1 1 0 0
1 0 0 0 0 0
1 0 1 0 0 0
1 1 0 0 0 0
1 1 0 1 0 0
1 0 0 1 0 0
1 1 1 0 0 0
1 1 1 1 0 0
1 0 1 1 0 0
0 1 1 0 0 0

Sample Output

5
4

题意大概是问你最少要多少根二极管就能把所有的排列区分出来。。。

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<string.h>
using namespace std;
int mat[105][20];
int main()
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    int p,n;
    while(T--)
    {
        scanf("%d%d",&p,&n);
        for(int i=1;i<=n;i++)
        for(int j=1;j<=p;j++)
        scanf("%d",&mat[i-1][j-1]);
        int ans=500;
        int choose[20];
        for(int i=1;i<(1<<p);i++)
        {
            bool flag=true;
            memset(choose,0,sizeof(choose));
            int k=0;
            for(k=0;(1<<k)<=i;k++)
                if((1<<k)&i)choose[k]=1;
            for(int i_=0;flag&&i_<n;i_++)
            for(int j=i_+1;flag&&j<n;j++){
                bool t=true;///相同的
                for(int l=0;t&&l<k;l++)if(choose[l])
                {
                    if(mat[i_][l]!=mat[j][l])t=false;///没有相同的
                }
                if(t)flag=false;///有相同的失败
            }
            if(flag){
                int temp=0;
                for(int c=0;c<k;c++)if(choose[c])temp++;
                ans=min(ans,temp);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

UVA 11205 The broken pedometer(子集枚举)

时间: 2024-08-28 17:09:39

UVA 11205 The broken pedometer(子集枚举)的相关文章

uva 11205 The broken pedometer(暴力枚举+子集生成)

我终于可以说这是我自己独立完成的题目了,没看题解,没看注释,虽然用的时间成了写,总归有成就感的,昨天晚上就写了个大概,有点bug,由于太晚了,而且有点困了,就去睡了,当时真是自己认真想了的,,很深入的想了,用的书上刚学会的位向量自己生成来判断的.以后都要努力自己想,自己解决,专注...深入.... 思路: 就是先算出最少用m个灯才能表示n个数字,然后找第一个数字(由许多灯组成的0,1序列)的个数为m的子 集,把这n个子集作为n个数字的下标,判断一下有没有玩去一样的,如果有的话证明这两个数字不能通

UVa 11205 - The broken pedometer

题目:给你p个LED组成的相同的显示器n个,每个显示器上显示一个符号(LED的p长度的01串) 问最少使用p位中的几个位,就能区分这n个不同符号,均不相同即可(其他位当做置0处理) 分析:搜索.枚举.从保留1位开始,一直搜索到p为,出现满足题意的解就退出,即可. 枚举采用位运算,提高效率. 说明:寻找相同的时候,先排序,再判断相邻的即可(n lg(n)):也可以使用hash提高效率. #include <algorithm> #include <iostream> #include

uva 11205 The broken pedometer (暴力)

uva 11205 The broken pedometer The Problem A marathon runner uses a pedometer with which he is having problems. In the pedometer the symbols are represented by seven segments (or LEDs): But the pedometer does not work properly (possibly the sweat aff

UVa 11025 The broken pedometer【枚举子集】

题意:给出一个矩阵,这个矩阵由n个数的二进制表示,p表示用p位二进制来表示的一个数 问最少用多少列就能将这n个数区分开 枚举子集,然后统计每一种子集用了多少列,维护一个最小值 b[i]==1代表的是选择了这一列 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector&g

uva11205 The broken pedometer 子集生成

PS:此题我在网上找了很久的题解,发现前面好多题解的都是没有指导意义的.后来终于找到了一篇好的题解. 好的题解的链接:http://blog.csdn.net/u013382399/article/details/23516051 我在他的解题的基础上,有了自己的理解. 题意: 有n(100以内)个位数为p(15以内)的二进制数,最少需要几个二进制位就可以把他们区分开. 题目分析: 数据较小,用的是暴力的方法,就是枚举每一个二进制位取或不取.就是相当于是枚举矩阵的列. 刘汝佳的小白书120页提到

uva 11825 Hackers&amp;#39; Crackdown (状压dp,子集枚举)

题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪(没有计算机有该项服务). 思路:(见大白70页,我的方程与大白不同) 把n个集合P1.P2.Pn分成尽量多的组,使得每组中全部集合的并集等于全集,这里的集合Pi是计算机i及其相邻计算机的集合,用cover[i]表示若干Pi的集合S中全部集合的并集,dp[s]表示子集s最多能够分成多少组,则 假设co

uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有相同的n种服务),对每台计算机,你可以选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让更多的服务瘫痪(没有计算机有该项服务). 思路:(见大白70页,我的方程与大白不同) 把n个集合P1.P2.Pn分成尽量多的组,使得每组中所有集合的并集等于全集,这里的集合Pi是计算机i及其相邻计算机的集合,用cover[i]表示若干Pi的集合S中所有集合的并集,dp[s]表示子集s最多可以分成多少组,则 如果cove

【UVA】11464-Even Parity(二进制枚举子集)

枚举第一行的所有可能情况,之后根据上面行计算下面行(判断是否冲突),获得最终结果. 14058243 11464 Even Parity Accepted C++ 0.275 2014-08-18 05:14:15 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<stack> #inc

The broken pedometer-纯暴力枚举

The broken pedometer Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  The Broken Pedometer  The Problem A marathon runner uses a pedometer with which he is having problems. In the pedometer the symb