POJ2185 Milking Grid KMP两次(二维KMP)较难
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const long long modn=;
char a[maxn][]={};
char s[]={};
int nex[maxn]={};
int f[]={};
int n,m;
int main(){
scanf("%d%d",&n,&m);
int x,y;
for(int i=;i<n;i++){
scanf("%s",&a[i]);
strcpy(s,a[i]);
for(int j=m-;j>;j--){
s[j]=;
for(x=,y=;a[i][y];x++,y++){//x for s,y for a if(s[x]==){
x=;
}
if(s[x]!=a[i][y]){
break;
}
}
if(!a[i][y]){
f[j]++;
}
}
}
int i,j;
for(i=;i<m;i++){
if(f[i]==n){
break;
}
}int cnt=i;
j=-,nex[]=-,i=;
while(i<n){
if(j==-||strcmp(a[i],a[j])==){
nex[++i]=++j;
}else{
j=nex[j];
}
}
printf("%d",(n-nex[n])*cnt);
return ;
}
POJ2185 Milking Grid KMP两次(二维KMP)较难的更多相关文章
- CSS Grid基于网格的二维布局系统(详细教程)
.grid-wrap{ display: inline-flex; padding: 20px; background: #f4f4f4; word-break: initial; } .handle ...
- POJ_2185_二维KMP
http://poj.org/problem?id=2185 求最小覆盖矩阵,把KMP扩展到二维,行一次,列一次,取最小覆盖线段相乘即可. #include<iostream> #incl ...
- Match:Milking Grid(二维KMP算法)(POJ 2185)
奶牛矩阵 题目大意:给定一个矩阵,要你找到一个最小的矩阵,这个矩阵的无限扩充的矩阵包含着原来的矩阵 思路:乍一看这一题确实很那做,因为我们不知道最小矩阵的位置,但是仔细一想,如果我们能把矩阵都放在左上 ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- POJ 2185 - Milking Grid (二维KMP)
题意:给出一个字符矩形,问找到一个最小的字符矩形,令它无限复制之后包含原来的矩形. 此题用KMP+枚举来做. 一维的字符串匹配问题可以用KMP来解决.但是二维的就很难下手.我们可以将二维问题转化为一维 ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- POJ2185 Milking Grid 【lcm】【KMP】
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- poj2185 Milking Grid【KMP】
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10084 Accepted: 4371 Des ...
- POJ2185 Milking Grid 题解 KMP算法
题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next ...
随机推荐
- centos下搭建YII环境
第一步:安装lnmp wget -c http://soft.vpser.net/lnmp/lnmp1.4-full.tar.gz 下载完lnmp后,进行解压文档 tar zxf lnmp1.4- ...
- 【leetcode 简单】第十题 实现strStr()
实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如果不存在,则返 ...
- input只读属性readonly和disabled的区别
主要区别: 参考: http://bbs.html5cn.org/forum.php?mod=viewthread&tid=84113&highlight=input http://b ...
- cookie、localstroage与sessionstroage的一些优缺点
1. Cookie 在前端开发中,尽量少用cooie,原因: (1) cookie限制大小,约4k左右,不适合存储业务数据,尤其是数据量较大的值: (2) cookie会每次随http请 ...
- Wireshark抓包保存文件(图片,视频,音频等)
1.首先选择一个图片的分组 如图的9801 就是JPG 2.对下面的窗口里面选中JPEG File Interchange Format 右键选择 导出分组字节流 3.文件输入XXX.jpg,注意保存 ...
- sicily 1193. Up the Stairs
Time Limit: 1sec Memory Limit:32MB Description John is moving to the penthouse of a tall sky-scr ...
- Deploy Openstack with RDO and Change VNC console to Spice
Deploy Openstack with RDO and Change VNC console to Spice host os: centOS 7 server config network an ...
- fprintf输出到文件中,sprintf输出到字符串中. 如: fprintf(fp,"%s",name); fp为文件指针 sprintf(buff,"%s",name); buff为字符数组
fprintf输出到文件中,sprintf输出到字符串中. 如: fprintf(fp,"%s",name); fp为文件指针 sprintf(buff,"%s" ...
- 【转载】python-协程
转载自:廖雪峰的官方网站 协程,又称微线程,纤程.英文名Coroutine. 协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用. 子程序,或者称为函数,在所有语言中都是层 ...
- laravel5.1--数据库操作
1 配置信息 1.1配置目录: config/database.php 1.2配置多个数据库 //默认的数据库 'mysql' => [ 'driver' => 'mysql', 'hos ...