# Character Recognition

## Description

Character recognition is the conversion of images into text. For now we consider each character in the picture is a N*M matrix with only zeros and ones, and we need to recognize K characters. You are to write a program to find minimal number of pixels so that we can recognize each character .For example, we have only two characters ‘T’ and ‘L’, and the matrix size is 3*3, we can think ‘T’ and ‘L’ are 111 100 010 100 010 111 so we can recognize the character with only bottom-left pixel, the answer is 1.

## Limits

-Memory limit per test: 256 megabytes
-Time limit per test: The faster the better

## Compile & Environment

### C++

g++ Main.cc –o Main –fno-asm –Wall –lm –static –std=c++0x –DONLINE_JUDGE

### Java

J2SE8
Maximum stack size is 50m

## Input

The first line of input is three integers N, M, K(1<=N,M<=10,2<=K<=6). Which represents the size of matrix and number of characters . Then is following K blocks, which represents the matrix. Notice that each block starts with a black line.

## Output

You should output the minimum number of pixels, which is the answer.

2 3 2
111
010
100
100

1

## Code

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define MAX 101
//MAX 取决于 M*N

using namespace std;
vector<vector<int>> arr_num; //用来存放所有的组合可能
vector<string> vec;
int a[MAX] = {0};

//生成组合情况的函数,组合情况保存在arr中
void comb_number(int n, int r){
if (r == 1){
a[r - 1] = n;
int j = 0;
while (a[j] != 0){
j++;
}
vector<int> tmp;
for (int  i = j - 1; i >= 0; i--){
tmp.push_back(a[i]);
}
arr_num.push_back(tmp);
}
else{
a[r - 1] = n;
for (int j = n - 1; j >= r - 1; j--){
comb_number(j, r - 1);
}
}
}

void comb_str(vector<vector<string>> &str,int K){
for(int i = 0; i < arr_num.size(); i++){
vector<string> str_tmp;
for (int j = 0; j < K; j++){
string tmp;
for (int m = 0; m < arr_num[0].size(); m++){
tmp += vec[j][arr_num[i][m]-1];
}
str_tmp.push_back(tmp);
}
str.push_back(str_tmp);
}
}

bool judge(vector<vector<string>> &str){
for (int i = 0; i < str.size();i++){
int flag = -1;
vector<string> tmp(str[i]);
for (int j = 0; j<str[0].size();j++){
for (int k = 0;k < str[0].size(); k++){
if (k==j){
continue;
}
else
{
flag = (tmp[j]).compare(tmp[k]);
}
if (flag == 0)
break;
}
}
if (flag == -1)
return true;
}
return false;
}

int main(){
int N, M, K;
cin >> N >> M >> K;

//Input
while (K--){
string str;
for (int i = 0; i<N; i++){
string tmp;
cin >> tmp;
str += tmp;
}
vec.push_back(str);  //vec中存有所有字符的表达
}
//尝试所有可能 1 到 N*M的长度
int len = 1;
for (; len <= N*M; len++){
arr_num.clear();
for (int i = N*M; i >= len;i--){
comb_number(i, len);
}

vector<vector<string>> str;
comb_str(str,vec.size());
if (judge(str))
break;
}
cout << len << endl;
return 0;
}

0152bc39-710d-47f8-8995-bf99b2c21bde

f16aa9ba-64bb-4cf2-879e-a5df7f622134

• 本文已收录于以下专栏：

## USACO Character Recognition 解题报告

• thestoryofsnow
• 2014年10月15日 11:28
• 998

## Exam 1 Character Recognition - Works Application 16

Character Recognition Description Character recognition is the conversion of images into text...
• woainiwss
• 2016年06月08日 20:34
• 3661

## chinese character recognition using Tesseract OCR

I have been using Tesseract 3.0.2 OCR SDK for image text extraction. But if I use chinese text i...
• yuanya
• 2014年08月14日 14:28
• 3411

## OCR 资料 Optical character recognition

http://www.explainthatstuff.com/how-ocr-works.html What is OCR? As you read these words on y...
• haluoluo211
• 2017年01月04日 10:32
• 598

## Works Application面试总结

2015年秋Works Application面试总结
• liuyan731
• 2015年12月25日 16:27
• 6298

## opencv 11 OCR 字符识别(character_recognition) vs2015

opencv_contrib自带的OCR处理用例共有6个，其中end_to_end_recognition、segmented_word_recognition可以使用tesseract库。 01 资...
• longji
• 2017年10月18日 09:33
• 486

## Optical character recognition

• 2013年01月14日 22:25
• 381KB
• 下载

## Exam 2 Maximum Xor with Prefix and Suffix - Works Application 16

Maximum Xor with Prefix and Suffix Description We have N numbers as an array, you need to fin...
• woainiwss
• 2016年06月06日 20:57
• 4505

## 光学字符识别（OCR，Optical Character Recognition）

• wanghhm2014
• 2017年09月25日 09:43
• 417

举报原因： 您举报文章：Exam 1 Character Recognition - Works Application 16 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)