UVA 11205 The broken pedometer

分析

使用一些LED灯的亮与灭来拼出一些数字,问如果拿去一些LED灯,是否还能区别这些数字呢?输出需要的最小的LED灯的数量。

这里,需要生成排列,即使用哪一些LED灯的排列,这里使用0,1表示使用或不使用,标记于flag数组中。

对于每一种排列,尝试把数字用这种方式表达(转换为十进制),再与其他的数字表达比较是否重复,如果重复说明这种排列不能区分,如果不重复则更新最小数量M

代码

#include <cstdio>
#define MAX_N 105
#define MAX_P 20

int P, N, M;
int led[MAX_N][MAX_P];
int a[MAX_N];
int flag[MAX_P];

void judge()
{
    int set_size = 0, idx = 0;
    for (int i = 0; i < P; i++)
        if (flag[i]) set_size++;
    if (set_size >= M) return;

    for (int i = 0; i < N; i++) {
        int cur_num = 0;
        for (int j = 0; j < P; j++)
            if (flag[j] && led[i][j])
                cur_num += (1<<j);
        for (int j = 0; j < idx; j++)
            if (a[j] == cur_num) return;
        a[idx++] = cur_num;
    }
    if (set_size < M) M = set_size;
}

void sub_set(int cur)
{
    if (cur == P) { judge(); return; }
    flag[cur] = 0; sub_set(cur + 1);
    flag[cur] = 1; sub_set(cur + 1);
}

void solve()
{
    M = P;
    sub_set(0);
    printf("%d\n", M);
}

int main()
{
    int T;
    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", &led[i][j]);
        solve();
    }
    return 0;
}

题目

Description

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

8

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:

0123456789

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

5

numbers 2 and 3 are seen as:

23

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

A

the numbers are seen as:

0123456789

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:

8

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.

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip
综合小区管理系统管理系统按照操作主体分为管理员和用户。管理员的功能包括报修管理、车位管理、车位分配管理、出入管理、字典管理、房屋管理、物业费缴纳管理、公告管理、物业人员投诉管理、我的私信管理、物业人员管理、用户管理、管理员管理。用户的功能包括管理部门以及部门岗位信息,管理招聘信息,培训信息,薪资信息等。该系统采用了Mysql数据库,Java语言,Spring Boot框架等技术进行编程实现。 综合小区管理系统管理系统可以提高综合小区管理系统信息管理问题的解决效率,优化综合小区管理系统信息处理流程,保证综合小区管理系统信息数据的安全,它是一个非常可靠,非常安全的应用程序。 管理员权限操作的功能包括管理公告,管理综合小区管理系统信息,包括出入管理,报修管理,报修管理,物业费缴纳等,可以管理操作员。 出入管理界面,管理员在出入管理界面中可以对界面中显示,可以对招聘信息的招聘状态进行查看,可以添加新的招聘信息等。报修管理界面,管理员在报修管理界面中查看奖罚种类信息,奖罚描述信息,新增奖惩信息等。车位管理界面,管理员在车位管理界面中新增。公告管理界面,管理员在公告管理界面查看公告的工作状态,可以对公告的数据进行导出,可以添加新公告的信息,可以编辑公告信息,删除公告信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值