poj 2185 (KMP)
完全不会啊……
附一份题解:http://blog.sina.com.cn/s/blog_69c3f0410100tyjl.html
var i,j,k,r,c,x:longint;
ch:array[..,..] of char;
s:string;
rr,cc:array[..] of boolean;
pre:array[..] of longint;
procedure init;
begin
readln(r,c);
for i:= to r do
begin
readln(s);
for j:= to c do ch[i,j]:=s[j];
end;
end;
procedure main;
begin
fillchar(rr,sizeof(rr),true);
fillchar(cc,sizeof(cc),true);
for x:= to r do
begin
pre[]:=;k:=;
for i:= to c do
begin
while (k<>) and (ch[x,k+]<>ch[x,i]) do k:=pre[k];
if ch[x,k+]=ch[x,i] then inc(k);
pre[i]:=k;
end;
k:=c;
for i:= to c do
if c-pre[k]<>i then cc[i]:=false else k:=pre[k];
end;
for x:= to c do
begin
pre[]:=;k:=;
for i:= to r do
begin
while (k<>) and (ch[k+,x]<>ch[i,x]) do k:=pre[k];
if ch[k+,x]=ch[i,x] then inc(k);
pre[i]:=k;
end;
k:=r;
for i:= to r do
if r-pre[k]<>i then rr[i]:=false else k:=pre[k];
end;
for i:= to r do if rr[i] then break;
for j:= to c do if cc[j] then break;
writeln(i*j);
end;
begin
init;
main;
end.
if c-pre[k]<>i then cc[i]:=false else k:=pre[k];
if r-pre[k]<>i then rr[i]:=false else k:=pre[k];
这两句话到底什么意思?
poj 2185 (KMP)的更多相关文章
- Oulipo POJ - 3461(kmp,求重叠匹配个数)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- POJ - 3461 (kmp)
题目链接:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- 剪花布条 HDU - 2087(kmp,求不重叠匹配个数)
Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input 输入 ...
- POJ 1961 2406 (KMP,最小循环节,循环周期)
关于KMP的最短循环节.循环周期,请戳: http://www.cnblogs.com/chenxiwenruo/p/3546457.html (KMP模板,最小循环节) POJ 2406 Powe ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- Milking Grid POJ - 2185 || 最小覆盖子串
Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时 ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Luogu 3375 【模板】KMP字符串匹配(KMP算法)
Luogu 3375 [模板]KMP字符串匹配(KMP算法) Description 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来 ...
随机推荐
- 由于Linux操作平台屡次受到黑客的“青睐”,LINUX公司也越来越注重产品的安全问题。
Guardian Digital公司和安全管理服务提供商(MSSP)Guardent公司推出的新产品将提高开放式源代码和Linux产品的安全性能. Guardian Digital公司将于本月底在纽约 ...
- 利用rlwrap配置linux下oracle sqlplus 历史记录回调
.下载rlwrap wget http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap-0.42.tar.gz .解压 tar -xvzf rlwrap-0.4 ...
- google其他入口地址
http://178.45.251.74/ http://64.233.166.51/ http://61.19.1.117/ http://64.233.166.42/ http://61.19.1 ...
- Python垃圾回收机制详解
一.垃圾回收机制 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺陷是循环引用的问题. 在Python中,如果一个对象的引用数为0,Python虚拟机就会回收这个对象的内存. #e ...
- Oracle中对象权限与系统权限revoke
实验: 1.以sys登陆,创建用户test1, test2: 2.授予test1系统权限(带admin option)-connect,授予test1对象权限(带grant option)-selec ...
- oracle中的隐式提交(auto commit)
通常我们执行sql或pl/sql时,需要我们手工提交.这样才能使所做的更改永久保存到数据库. 但有时即使我们没有在sql或pl/sql中发出commit命令,所做的更改也会被提交.这种提交是在某些特定 ...
- 详解Google-ProtoBuf中结构化数据的编码
本文的主要内容是google protobuf中序列化数据时用到的编码规则,但是,介绍具体的编码规则之前,我觉得有必要先简单介绍一下google protobuf.因此,本文首先会介绍一些google ...
- 请给出一个左侧定宽右侧自适应的HTML结构及样式
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- 微软职位内部推荐-This Job is no longer available.
微软近期Open的职位: 如果你想试试这个职位,请跟我联系,我是微软的员工,可以做内部推荐.发你的中英文简历到我的邮箱:Nicholas.lu.mail(at)gmail.com
- python 练习题
python是一个功能很强大的语言,他可以解决各种在数学问题,下面我分享一些练习题供大家参考: 有关正态分布的问题: # -*- coding: cp936 -*- import math a=0 u ...