UVA 11205 The Broken Pedometer (violence)

Source: Internet
Author: User

UVA 11205 The Broken pedometer

The problem

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

But the pedometer does does properly (possibly the sweat affected the batteries) and only some of the LEDs is active. The runner wants to know if all the possible symbols:

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

Numbers 2 and 3 are seen as:

So they cannot is distinguished. But when the active LEDs is:

The numbers is seen as:

And all of them has a different representation.

Because the runner teaches algorithms at University, and he had some hours to think while he was running, he had 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 NumberP of LEDs, and N symbols to is represented with these LEDs (along with the codification of each s Ymbol).

For example, the previous sampleP = 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), andn lines each one with the codification of a symbol. For each symbol, the codification are 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 ofP is a and the maximum value of N is 100. All the symbols has different codifications.

The Output

The output would consist of a line for each problem, with the minimum number of active LEDs necessary to identify all the G Iven symbols.

Sample Input
27101 1 1 0 1 1 10 0 1 0 0 1 01 0 1 1 1 0 11 0 1 1 0 1 10 1 1 1 0 1 01 1 0 1 0 1 11 1 0 1 1 1 11 0 1 0 0 1 01 1 1 1 1 0 1 16100 1 1 1 0 01 0 0 0 0 01 0 1 0 0 01 1 0 0 0 01 1 0 1 0 01 0 0 1 0 01 1 1 0 0 01 1 1 1 0 01 0 1 1 0 00 1 1 0 0 0
Sample Output
54


The main idea: the first data represents a few sets of data, the next two data is the number of LEDs can be lit n, and the number of characters to be expressed in M, followed by the M row n column of data, requiring a minimum of only a few LED lights can represent that m data.

Problem-solving ideas: I borrowed from the great God's code, first enumerate the number of lights, and then by the number of lights enumerated all the composition of the situation, if there is a set of requirements, that is, the current number of lights, otherwise the number of lights +1.


#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int a[105][20], t[20], M, n;int judge (int a, int b, int sum)  {for  (int i = 1; I <= sum; i++)  {  if (a[a][t[i]]! = A[b][t[i]]) 
   return 0;  }  return 1;  }  int find (int k)  {for  (int a = 0; a < n; a++) {for (int b = a + 1; b < n; b++) {if (judge (A, B, K)) {Retur n 0;}}}  return 1;  }  int build (int sum, int k)  {  if (sum! = k-1)  {for  (t[k] = t[k-1] + 1; T[k] < m; t[k]++) {if (Build (sum, K + 1)) {return 1;}}  } else  {  if (find (sum)) {return 1;}  } return 0;  }  int main () {int num;while (scanf ("%d", &num) = = 1) {while (scanf ("%d\n%d", &m, &n) = = 2) {for (int i = 0; I &l T N i++) {for (int j = 0; J < m; J + +) {scanf ("%d", &a[i][j]);}} int i;  for (i = 0; I <= m; i++)  {  memset (t, 0, sizeof (t));  T[0] =-1;  if (build (i,1)) {break;}  }  printf ("%d\n", I);  }} return 0;}



UVA 11205 The Broken Pedometer (violence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.