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, ...
随机推荐
- 【 henuacm2016级暑期训练-动态规划专题 A 】Cards
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 很显然只要维护B,R,G的数量就好了. 可以很容易想到一个dfs(int a,int b,int c) 然后如果a+b+c==1,那 ...
- 解析如何利用ElasticSearch和Redis检索和存储十亿信息
如果从企业应用的生存率来看,选择企业团队信息作为主要业务,HipChat的起点绝非主流:但是如果从赚钱的角度上看,企业市场的高收益确实值得任何公司追逐,这也正是像JIRA和Confluence这样的智 ...
- Ubuntu PostgreSql主从切换
主机:192.168.100.70 从机:192.168.100.71 通用配置(即主从都要配置) 修改/etc/postgresql/10/main/pg_hba.conf host all all ...
- stl里面stack的注意事项
1. pop是不返回元素的.因为不能返回引用,只能返回实例.而这个实例是在函数里面初始化的,所以必须在外面再赋值和初始化.而如果实例复制失败,会产生丢失. 2. 而top是可以返回引用的.实际上,返回 ...
- Cocos2d-x-lua学习点滴
Lua下的方法.自己项目经验,个人见解,不能确保正确. Sprite: local Light = CCSprite:create("light.png") ...
- WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享
WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享 在WinForm程序中,我们有时须要对某容器内的全部控件做批量操作.如批量推断是否同意为空?批量设置为仅仅读.批量 ...
- 四种GCC内置位运算函数
int __builtin_ffs (unsigned int x) 返回x的最后一位1的是从后向前第几位,比方7368(1110011001000)返回4. int __builtin_clz (u ...
- luogu 2869 挑剔的美食家
Gourmet Grazers 传送门 题目大意 约翰的奶牛对食物越来越挑剔了.现在,商店有\(M\) 份牧草可供出售,奶牛食量很大,每份牧草仅能供一头奶牛食用.第\(i\) 份牧草的价格为\(P_i ...
- C# 位域[flags]
.NET中的枚举我们一般有两种用法,一是表示唯一的元素序列,例如一周里的各天:还有就是用来表示多种复合的状态.这个时候一般需要为枚举加上[Flags]特性标记为位域,例如: [Flags] enu ...
- Win7 如何禁用“切换用户”功能
1.按win+r,输入gpedit.msc,点击确定: 2.依次点击计算机配置--管理模块--系统--登录,右侧列表中找到“隐藏“快速用户切换”的入口点”: 3.双击隐藏“快速用户切换”的入口点,点击 ...