UVA 11205 The broken pedometer 状态压缩+搜索

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情
 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 <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int n,p;
int vis[111],res;
bool b[1<<16];

void solve()
{
    int i,j;
    int sum=(1<<p)-1;
    for(i=0;i<=sum;i++)
    {
        memset(b,false,sizeof(b));
        for(j=0;j<n;++j)
        {
            int val=i&vis[j];
            if(b[val])
                break;
            else
                b[val]=true;
        }
        if(j==n)
        {
            int ans=0;
            int a=i;
            while(a>0)
            {
               if(a&1)
                    ans++;
               a=a>>1;
            }
            res=min(ans,res);
        }
    }
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(b,false,sizeof(b));
        memset(vis,0,sizeof(vis));
        int i,j,c;
        cin>>p>>n;
        for(i=0;i<n;i++)
        {
            for(j=0;j<p;j++)
            {
                scanf("%d",&c);
                if(c)
                vis[i]+=(c<<j);
            }
        }
        res=p;
        solve();
        cout<<res<<endl;

    }
}


UVaOJ 11205 - The broken pedometer ——by A Code Rabbit Description 有p个LED灯,可以组成一个灯牌。 灯牌上可以显示一些有意义的符号,比如显示数字啥的。 现在有n个灯牌,显示的符号各不相同。 问你最少用几个LED灯,就可以区别这些符号。 输入n和p。 输出最少LED灯数。 Types Brute Force :: Elementary Skil 阅读详情

相关推荐

UVA11205 The broken pedometer【位运算+暴力】

A marathon runner uses a pedometer with which he is having problems. In the pedometer the symbols are represented by seven segments (or LEDs): 问题链接:UVA11205 The broken pedometer 问题简述:(略) 问题分析: &amp;amp;amp;amp;nbsp;&amp;amp;amp;amp;...

海岛Blog 659

The broken pedometer-纯暴力枚举

The broken pedometer Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  The Broken Pedometer  T

qq_18661257的专栏 770

UVA 11205 The broken pedometer

题目如下: 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

hexiecs的技术专栏 904

UVa 11205 The broken pedometer (枚举好题&巧用二进制)

11205 - The broken pedometer Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=107&amp;page=show_problem&amp;problem=2146 The Probl...

844604778 165

UVA11205The broken pedometer,思路+代码,可能是最不装逼最朴素最易懂效率也最差的代码。

#include #include #include #include #include using namespace std; /** Problem : UVA11205 - The broken pedometer Begin Time: 28th/Mar/2012 11:30 a.m. Finish Time: 29th/Mar/2012 2:14 a.

c0de4fun的完美算(nei)法(he)教室-我们仍不知道,那天调用的驱动的名字。 3455

UVA-11205 The Broken Pedometer 模拟 + 状态压缩

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)...

weixin_34044273的博客 88

uva-11205-枚举子集

uva-11205-枚举子集   题意: 至少用多少列来表示输入中的二进制数,并且表示的数里面没有重复,最多P列,N个二进制数 所以......表示的最大二进制数是2^P,那么在2^P方内的数二进制最大值是P个1,最小是0,所以,枚举2^P次方内的数k.和输入的二进制余,判断是否会重复, 如果没有重复,把k里面二进制是1的拿出来就是我们枚...

weixin_34290352的博客 147

Genspark 6.0 SecondBrain:构建个人记忆系统的AI智能体技术解析

AI智能体作为人工智能技术的重要分支,其核心原理是通过机器学习算法模拟人类认知过程,实现自主决策和任务执行。在技术价值层面,智能体系统能够显著提升人机协作效率,减少重复性工作负担。向量化存储和知识图谱构建是支撑智能体长期记忆能力的关键技术,通过将交互信息转化为高维向量表示,系统能够实现语义级别的相似性检索和上下文关联。在实际应用场景中,这类技术特别适合需要持续学习和个性化适应的开发环境,如Genspark 6.0的SecondBrain系统就通过动态知识图谱和主动学习机制,为开发者构建了真正理解长期需求的个

dingdi3021的博客 427

UVA 11205

第一次做到这么暴力的题,我看题的时候被吓到了。。。除了枚举想不出别的算法了,但是枚举好像效率很低,但是算一算就知道15个灯泡有2^15种组合方式,枚举量也就3W左右,每次需要判断100+99+……+1次,数量级是10^3,总的算下来一次数据是10^7,这样的效率应该也够了,看了下别人的写法也是直接暴力。。。。代码附上 #include #include #include using nam

废弃。。 549

uva11205

题意理解了就不难了,就是问取多少列能区分所有行,列可以是不连续的 #include #include #include #include #include #include int n,p,min,a[200][20],used[20]; char s[200][20]; void change(int *A,int cc) { int i,j,num; for(i=0;i<n;

小周的专栏 1151

UVa 11205 损坏的步数计

题意:有一组编码,用其中最少的位数来区分这些编码。 思路:相当于枚举一个集合的所有子集,然后选择符合要求的势最小的集合。             子集生成有三种方法,但每一种子集的生成都没有明显的规律,至少不是从1个元素、2个元素到n个元素这样的顺序生成的,所以还是要枚举出所有的子集才行。这里用的增量构造法来枚举子集。 Code: #include void print_subset(i

buxizhizhou530的专栏 1151

11205 - The broken pedometer

语言:C++描述:这道题其实一开始自己就是错误思维,题目就是通过最少的二进制位表示所有的数,也就是说存在自由组合的问题,不过存在这样的问题:如果一列二进制数被删去后,可以使列数减一来表示了所有的数了,但是有可能列数只会减一,输出的结果就是列数-1了,也就是说其他还有可能的情况都被封锁了。所以,原本的方法出现了错误,虽然测试数据过了,但是uva测试数据过不了,然后不得不根据刘汝佳书上的位向量法改写了

moyan_min的专栏 864

uva11205 The broken pedometer

计时器坏了 判断至少几列数字可以判断出这几个数字 子集 位向量法 #include #include int mat[105][20], b[20]; int min, p, n; void subset(int cur){ if (cur == p) { for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n;

katydid3018的博客 459

UVa 11205 - The broken pedometer

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

小白菜又菜 1721

uva 11205 The Broken Pedometer

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

不慌不忙、不急不躁 1337

UVa-11205-The broken pedometer

AOAPC I: Beginning Algorithm Contests (Rujia Liu)::Volume 3. Brute Force::Elementary Skills // 11205 - The broken pedometer #include <iostream> #include <cstring> u...

abu47643的博客 166

uva11205-The broken pedometer(损坏的步数计)

对于我,这个题最大的障碍是理解题意,题意应是:找出最少的LED灯,使得给出的每个数字能够被识别出来,最后输出灯的个数即可。 最好的算法是子集生成法。此处我使用的是位向量子集生成法: 代码如下: #include #include int str[100][20]; int p, n, t, min, id[20]; void subset(int p, int cur) { if

稻草人 582

UVA11205

题目的意思就是在最少用几列,可以把所有行(代表一种zhuangtai)

潜水的程序猿 570
上一篇: poj 1976 A Mini Locomotive 01背包
下一篇: poj 3628 Bookshelf 2 01背包
Clearle
博客等级 码龄14年 15粉丝 235原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值