题目大意是字符串识别
一道细节很繁琐的DP,要用到很多数组
一开始还真看不出是DP,后来参考了别人的代码,然后又按自己的思路重头到尾写了,虽然速度不咋的

Executing...
Test 1: TEST OK [0.008 secs, 6504 KB]
Test 2: TEST OK [0.008 secs, 6504 KB]
Test 3: TEST OK [0.019 secs, 6504 KB]
Test 4: TEST OK [0.035 secs, 6504 KB]
Test 5: TEST OK [0.084 secs, 6504 KB]
Test 6: TEST OK [0.116 secs, 6504 KB]
Test 7: TEST OK [0.167 secs, 6504 KB]
Test 8: TEST OK [0.192 secs, 6504 KB]
Test 9: TEST OK [0.178 secs, 6504 KB]

All tests OK.
YOUR PROGRAM ('charrec') WORKED FIRST TIME! That's fantastic
-- and a rare thing. Please accept these special automated
congratulations.

 #include <stack>
#include <iostream>
#include <stdio.h>
#define R19 0
#define R20 1
#define R21 2
#define INF 1000000000
using namespace std; char ch[][][];
char mat[][];
int dif[][][];
int cost[][]; // cost[i][j]表示从mat的第i行开始匹配j行得到的最小差距
int optimalCh[][]; // optimalCh[i][j]表示从mat的第i行开始匹配j行最优的匹配字符
int d[]={}; // d[i]表示匹配到第i行所得到的最小差距
int step[]; // step[i]表示第i行开始的最优匹配的字符行数
// 得到行数中不同的个数
/*
num为第几个字符
l1为num字符的行数
l2为mat的行数
*/
int getDif(int num,int l1,int l2)
{
int sum=;
for(int i=;i<;i++)
{
if(ch[num][l1][i]!=mat[l2][i])
sum++;
}
return sum;
} // num为字符,l1为mat开始匹配的行数,del为删除了哪一行
int getCost(int num,int l1,int del)
{
int sum=;
for(int i=,p=;p<;i++,p++)
{
if(i==del)
i++;
sum+=dif[num][i][l1+p];
}
return sum;
} int getCost2(int num,int l1,int del)
{
int sum=;
for(int i=,p=;i<;i++,p++)
{
if(p==del)
p++;
sum+=dif[num][i][p+l1];
}
return sum;
} int main()
{
freopen("font.in","r",stdin);
int n; // 行数
cin>>n;
for(int i=;i<n/;i++)
{
for(int j=;j<;j++)
{
scanf("%s",ch[i][j]); }
} freopen("charrec.in","r",stdin);
freopen("charrec.out","w",stdout); cin>>n; for(int i=;i<n;i++)
scanf("%s",mat[i]); // 初始化dif数组
for(int i=;i<;i++)
for(int j=;j<;j++)
{
for(int k=;k<n;k++)
{
dif[i][j][k]=getDif(i,j,k);
}
} // 初始化cost
for(int i=;i<n;i++) // 从第i行开始匹配
{
cost[i][R19]=cost[i][R20]=cost[i][R21]=INF;
for(int j=;j<;j++) // 第j个字符
{
if(i+<n+)
{
for(int k=;k<;k++) // 删掉行数
{
if(cost[i][R19]>getCost(j,i,k))
{
cost[i][R19]=getCost(j,i,k);
optimalCh[i][R19]=j;
}
}
}
if(i+<n+)
{
if(cost[i][R20]>getCost(j,i,-))
{
cost[i][R20]=getCost(j,i,-);
optimalCh[i][R20]=j;
}
}
if(i+<n+)
{
for(int k=;k<;k++) // 多出的行数
{
if(cost[i][R21]>getCost2(j,i,k))
{
cost[i][R21]=getCost2(j,i,k);
optimalCh[i][R21]=j;
}
}
}
}
} fill_n(d,n+,INF);
// 初始值
d[]=cost[][R19];step[]=;
d[]=cost[][R20];step[]=;
d[]=cost[][R21];step[]=;
// DP
for(int i=;i<n;i++) // 匹配的最后一行为i
{
if(d[i-]+cost[i-][R19]<d[i])
{
d[i]=d[i-]+cost[i-][R19];
step[i]=;
}
if(d[i-]+cost[i-][R20]<d[i])
{
d[i]=d[i-]+cost[i-][R20];
step[i]=;
}
if(d[i-]+cost[i-][R21]<d[i])
{
d[i]=d[i-]+cost[i-][R21];
step[i]=;
}
} stack<int> S; for(int p=n-;p!=-;p=p-step[p])
{
S.push(optimalCh[p-step[p]+][step[p]-]);
} while(!S.empty())
{
int tmp=S.top();
S.pop();
printf("%c",tmp==?' ':tmp-+'a');
}
cout<<endl;
return ;
}

USACO5.4-Character Recognition的更多相关文章

  1. USACO 5.4 Character Recognition

    Character Recognition This problem requires you to write a program that performs character recogniti ...

  2. OCR (Optical Character Recognition,光学字符识别)

    OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形状翻译 ...

  3. csharp:Optical Character Recognition

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. 图片OCR(Optical Character Recognition)

    目录 Photo OCR问题描述 滑动窗口(Sliding Windows) 获得大量数据和人工数据(Getting Logs of Data and Artificial Data) 瓶颈分析:需要 ...

  5. USACO 5.4 Character Recognition(DP)

    非常恶心的一题,卡了三个月,没什么动力做了,代码直接抄的别人的... 这题主要思路就是预处理出几个数组,再预处理出几个数组,最后DP,输出一下路径... 写起来挺非常麻烦,代码不贴了,丢人... 把U ...

  6. OCR(Optical Character Recognition)算法总结

    https://zhuanlan.zhihu.com/p/84815144 最全OCR资料汇总,awesome-OCR

  7. 第 38 章 OCR - Optical Character Recognition

    38.1. Tesseract 查找Tesseract安装包 $ apt-cache search Tesseract ocrodjvu - tool to perform OCR on DjVu d ...

  8. Online handwriting recognition using multi convolution neural networks

    w可以考虑从计算机的“机械性.重复性”特征去设计“低效的”算法. https://www.codeproject.com/articles/523074/webcontrols/ Online han ...

  9. 车牌识别1:License Plate Detection and Recognition in Unconstrained Scenarios阅读笔记

    一.WHAT 论文下载地址:License Plate Detection and Recognition in Unconstrained Scenarios [pdf] github 的项目地址: ...

  10. Tesseract-OCR字符识别简介

    OCR(Optical Character Recognition):光学字符识别,是指对图片文件中的文字进行分析识别,获取的过程.Tesseract:开源的OCR识别引擎,初期Tesseract引擎 ...

随机推荐

  1. cocoapods 的使用心得

    一般我们下载的demo里边含有cocoapods 我们需要 在终端上输入命令,让他能够成功运行 步骤如下: 打开终端  cd 项目目录  直接拖动到终端里边就可以, 然后 pod install 如果 ...

  2. Android的深度定制版阿里云os(Android的山寨)

    阿里云OS(YunOS)是阿里巴巴集团的智能手机操作系统,依托于阿里巴巴集团电子商务领域积累的经验和强大的云计算平台,基于LINUX开发. 魅族4阿里yun OS版已上市.[1] 1简介 阿 里云OS ...

  3. SPOJ 416 - Divisibility by 15(贪心)

    糟烂的代码啊...  这个题目思路很简单——末位只可能为0和5,所有数字的和肯定被3整除 没有0和5的肯定不行 否则,把所有数字求和 如果被3整除,则从大到小输出 如果除3余1,则按以下顺序——删1: ...

  4. js中时间戳与日期转换-js日期操作

    常用的一些日期操作. 用js获取一个时间戳. <script type="text/javascript"> var date = new Date();//当前时间 ...

  5. C++指针数组和数组指针

    指针相关问题 using namespace std; int main(){ //a) 一个整型数( An integer) int a; //b) 一个指向整型数的指针( A pointer to ...

  6. USB HID Report Descriptor 报告描述符详解

    Report descriptors are composed of pieces of information. Each piece of information is called an Ite ...

  7. AIX-df命令

    df 命令显示文件系统的总空间和可用空间信息.FileSystem 参数指定文件系统驻留的设备的名称,文件系统的安装目录或文件系统的相对路径名.File 参数指定非安装点的文件或目录.如果指定 Fil ...

  8. VritualBox 中Debian安装tool

    VritualBox 中Debian安装tool 环境 Debian 8 VirtualBox 配置Debian的源 #163源 deb http://mirrors.163.com/debian/ ...

  9. thinkphp 中 使用七牛云上传

    利用七牛云私有空间存储文件 第一步,注册七牛云,创建空间,将空间设为私有 需要记下的东西: AK,SK,bucket 第二步配置ThinkPHP 在config.php添加 'UPLOAD_SITEI ...

  10. 广播接收者 BroadcastReceiver 示例-2

    BaseActivity /**所有Activity的基类*/ public class BaseActivity extends Activity {     @Override     prote ...