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

id=19330" class="login ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; border:1px solid rgb(211,211,211); color:blue; font-size:12px!important">Submit Status

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
此题目最重要的是看懂,他的大概意思是给你个P代表着有多少位,给你个N代表着有多少个数
终于要你求。每个数改变同样的位(题目是直接删掉同样的位。即关掉LED,让他不能执行)。最多改变多少,剩下的位依然能够表示独特性。即每个数都不同样,都能够识别出来
所以直接用DFS枚举全部的情况(中间剪枝一小部分)就可以。
/*
Author: 2486
Memory: 0 KB Time: 33 MS
Language: C++ 4.8.2 Result: Accepted
VJ RunId: 4153206 Real RunId: 15826224
Public: No Yes
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,p,t,maps[105][105],Max,ind[20],ds[100+5];
bool vis[20];
bool C(int m) {
int s;
memset(vis,false,sizeof(vis));
for(int i=0; i<m; i++) {
vis[ind[i]]=true;
}
for(int i=0; i<n; i++) {
s=0;
for(int j=0; j<p; j++) {
if(!vis[j]) {
s=s*2+maps[i][j];
}
}
ds[i]=s;
}
sort(ds,ds+n);
for(int i=1; i<n; i++) {
if(ds[i]==ds[i-1])return false;
}
return true;
}
void dfs(int col,int num) {
if(!C(num))return;
if(col>=p) {
Max=max(Max,num);
return ;
}
ind[num]=col;
dfs(col+1,num+1);
dfs(col+1,num);
}
int main() {
scanf("%d",&t);
while(t--) {
scanf("%d%d",&p,&n);
for(int i=0; i<n; i++) {
for(int j=0; j<p; j++) {
scanf("%d",&maps[i][j]);
}
}
Max=0;
dfs(0,0);
printf("%d\n",p-Max);
}
return 0;
}

Submit Status

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. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  3. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  4. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  5. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  6. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  7. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

  8. POJ-3187 Backward Digit Sums (暴力枚举)

    http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #in ...

  9. hihoCoder #1179 : 永恒游戏 (暴力枚举)

    题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...

随机推荐

  1. 题解 P3978 【[TJOI2015]概率论】

    这道题...好像是第一道我自己切出来的黑题... 先说一句,牛顿二项式蒟蒻并不会,可以说是直接套结论. 求诸位老爷轻喷. 这道题用卡特兰数搞. 卡特兰数这玩意从普及组初赛一路考到省选,十分有用. 如果 ...

  2. 监控SQLserver计数器

  3. iOS-UIImage imageWithContentsOfFile 和 imageName 对照

    1.imageWithContentsOfFile NSString *imagePath = [NSString stringWithFormat:@"%@/%@",[[NSBu ...

  4. 手写一个节点大小平衡树(SBT)模板,留着用

    看了一下午,感觉有了些了解.应该没有错,有错希望斧正,感谢 #include<stdio.h> #include<string.h> struct s { int key,le ...

  5. node09---中间件

    如果我的的get.post回调函数中,没有next参数,那么就匹配上第一个路由,就不会往下匹配了. 如果想往下匹配的话,那么需要写next() 1app.get("/",funct ...

  6. vue keep-alive保存路由状态1 (接下篇)

    本文很长,但是很详细,请耐心看完就一目了然了有下篇 keep-alive 是 Vue 内置的一个组件,使被包含的组件保留状态,或避免重新渲染. 1. 基础用法,缓存所有路由: <keep-ali ...

  7. Spark 运行机制及原理分析

  8. WPF 样式

    样式是属性值的集合,能被应用到一个元素,类似CSS,每个控件最多只能有一个样式,通过控件的Stype属性应用样式,如下代码,其中BigFontButtonStyle是用于检索资源的关键字,也可以通过代 ...

  9. vue 初始化项目模板报错

    E:\xiaogezi.cn\vue>vue init webpack myProject vue-cli · Failed to download repo vuejs-templates/w ...

  10. MVC 设计模式

    MVC 设计模式: 最早由 Trygve Teenskaug 在 1978 年提出,上世纪 80 年代是程序语言 Smalltalk 的一种内部架构.后来 MVC 被其他领域借鉴,成为了软件工程中的一 ...