The broken pedometer-纯暴力枚举
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
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;
}
The broken pedometer-纯暴力枚举的更多相关文章
- UVA 11205 The broken pedometer(子集枚举)
B - The broken pedometer Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
- 51nod 1116 K进制下的大数 (暴力枚举)
题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- bzoj 1028 暴力枚举判断
昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...
- POJ-3187 Backward Digit Sums (暴力枚举)
http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #in ...
- hihoCoder #1179 : 永恒游戏 (暴力枚举)
题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...
随机推荐
- LoadRunner监控Window/Unix系统资源的配置
LoadRunner监控Window/Unix系统资源需要做两件事情: 1.配置被监视的服务器,以便于LoadRunner能够获取系统资源使用情况的数据 2.在LoadRunner的Controlle ...
- tring.Format格式化用法
(数字保留两位小数,且每隔3为用逗号隔开): string.format("1f,.2d",333) -->333.00 string.format("1f,.2d ...
- HDOJ 5294 Tricks Device 最短路(记录路径)+最小割
最短路记录路径,同一时候求出最短的路径上最少要有多少条边, 然后用在最短路上的边又一次构图后求最小割. Tricks Device Time Limit: 2000/1000 MS (Java/Oth ...
- 文件类似性推断 -- SimHash
近期调研了一下simhash算法,它主要用在谷歌网页去重中.网上有非常多原理性的介绍. 既然能够用来推断文件的相似性,就想知道效果怎么样.simhash的准确度是否依赖于分词算法?是否和simhash ...
- 主站sinox.org堵塞太厉害,大家用sinox.3322.org訪问
近期 www.sinox.org域名堵塞太厉害了.差点儿不能訪问,如今大家用sinox.3322.org訪问 sinox.org仅仅是显示正在建设 一直以来sinox.org仅仅是个摆设,并非主要域名 ...
- 使用TensorBoard可视化工具
title: 使用TensorBoard可视化工具 date: 2018-04-01 13:04:00 categories: deep learning tags: TensorFlow Tenso ...
- Ubuntu14.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)
不多说,直接上干货! 在这篇博客里,我采用了非官网的安装步骤,来进行安装.走了弯路,同时,也是不建议.因为在大数据领域和实际生产里,还是要走正规的为好. Ubuntu14.04下Mongodb(离线安 ...
- ASP.NET使用MergeInto做数据同步,同步SQLSERVER不同数据库的相同表结构的数据
public string SynchronousData() { ReturnJson Rejson = new ReturnJson(); //将WebConfig中的数据库连接name中的值写进 ...
- Linux部署之批量自动安装系统之NFS篇
1. 编辑配置文件让远端设备可访问vim /etc/exports 2. 启动服务
- ActiveMQ学习笔记(20)----Consumer高级特性(二)
1. Message Selectors JMS Selectors 用在获取消息的时候,可以基于消息属性和Xpath语法对消息进行过滤.JMS Selectors有SQL92语义定义.以下是个Sel ...