Milking Grid
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 6169   Accepted: 2573

Description

Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns.

Help FJ find the rectangular unit of smallest area that can be repetitively tiled to make up the entire milking grid. Note that the dimensions of the small rectangular unit do not necessarily need to divide evenly the dimensions of the entire milking grid, as indicated in the sample input below.

Input

* Line 1: Two space-separated integers: R and C

* Lines 2..R+1: The grid that the cows form, with an uppercase letter denoting each cow's breed. Each of the R input lines has C characters with no space or other intervening character.

Output

* Line 1: The area of the smallest unit from which the grid is formed 

Sample Input

2 5
ABABA
ABABA

Sample Output

2

Hint

The entire milking grid can be constructed from repetitions of the pattern 'AB'.

Source

 
 
这道题,题目不是很好懂,首先是  
aabcdeaa
acbdeead   
dakfdkkk      ---》求最小的子矩阵 其实很简单的呀,对一行求出最小的循环节点  对每一列求出最小的循环节点就行了max={max, RR-next[RR]} 
dasdsdd         max1 ={max1,CC-next[CC]};  然后相乘得到了他的面积:   max1*max ==ans;
 
 
代码:
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
const int row =;
const int cow =;
char str[row][cow];
int next[row][cow];
int RR,CC;
int main()
{
while(scanf("%d%d",&RR,&CC)!=EOF)
{
for(int i=;i<RR;i++)
scanf("%s",str[i]);
int i,j,k;
//先求出每一行的next
int max_row=-;
for(k=;k<RR;k++)
{
i=; j=-;
next[k][]=-;
while(i<CC)
{
if(j==-||str[k][i]==str[k][j])
{
i++;
j++;
next[k][i]=j;
}
else j=next[k][j];
}
if(max_row<(CC-next[k][CC]))
max_row=(CC-next[k][CC]);
}
int max_cow=-;
//求出所有列中的最小循环节
for(k=;k<CC;k++)
{
i=;
j=-;
next[][k]=-;
while(i<RR)
{
if(j==-||str[i][k]==str[j][k])
{
i++;
j++;
next[i][k]=j;
}
else
j=next[j][k];
}
if(max_cow<(RR-next[RR][k]))
max_cow=(RR-next[RR][k]);
}
printf("%d\n",max_row*max_cow);
}
return ;
}
 
 
 

POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)的更多相关文章

  1. POJ 2185 Milking Grid KMP循环节周期

    题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...

  2. 依据矩阵的二维相关系数进行OCR识别

    我想通过简单的模板匹配来进行图像识别. 把预处理好的字符图片,分别与A到Z的样本图片进行模板匹配. 结果最大的表明相关性最大,就能够识别字符图片了. 在实际应用中.我用了openCV的matchTem ...

  3. 牛客练习赛1 矩阵 字符串二维hash+二分

    题目 https://ac.nowcoder.com/acm/contest/2?&headNav=www#question 解析 我们对矩阵进行二维hash,所以每个子矩阵都有一个额hash ...

  4. 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都依照从左到右的递增的顺序排序,输入这种一个数组和一个数,推断数组中是否包括这个数

    // 二维数组中的查找,杨氏矩阵在一个二维数组中.每行都依照从左到右的递增的顺序排序. // 每列都依照从上到下递增的顺序排序.请完毕一个函数,输入这种一个数组和一个数.推断数组中是否包括这个数 #i ...

  5. 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185

    Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...

  6. POJ 2185 Milking Grid KMP(矩阵循环节)

                                                            Milking Grid Time Limit: 3000MS   Memory Lim ...

  7. poj 2185 Milking Grid

    Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS   Memory Limit: 65536K       Descript ...

  8. POJ 2185 Milking Grid [二维KMP next数组]

    传送门 直接转田神的了: Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6665   Accept ...

  9. 题解报告:poj 2185 Milking Grid(二维kmp)

    Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...

随机推荐

  1. 曲线救国,解决Mac系统下,Android sdk下载失败的问题

    Mac下翻_墙的问题 话说GFW屏蔽谷歌已经有一阵子了,最近打算在Mac系统下折腾个Android应用,备好了IDE,只欠SDK,无奈下载时因为GFW的缘故,总是失败,我心痛哉! 由于本人偏爱Mac系 ...

  2. Ajax发送POST请求的心路历程

    好多年前就在项目中用ajax实现了页面部分数据的发送,当时用的是GET方法. 这次用POST方法实现同样的功能,竟然花费了不少的时间! ① 关于JQuery ajax的配置项说明 url : 请求的u ...

  3. Action的搭建及application、request、Session的运用 多种方法

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. linux系统:rm-rf执行以后,怎么办?我来教你恢复文件。

    记得我当时也犯过这个错误 rm -rf /* 傻傻的盯着屏幕看... 还好当时是在自己的虚拟机里,没什么数据,打镜像恢复回来就好了.今天看到这篇文章,备用!嗯 是的 万一哪天脑抽了 --------- ...

  5. tomcat源码导入eclipse步骤

    1. 获取源代码 方式一:从官网http://tomcat.apache.org/download-70.cgi 直接下载,官网提供了Binary 和 Source Code两种下载方式,要研究tom ...

  6. 字符串处理:ABAP中的正则表达式

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  7. 删除List中制定的值的方法

    /** * * @param args */ public static void main(String[] args) { List<String> list = new ArrayL ...

  8. 12 Using_explain_plan

    The row source tree is the core of the execution plan. The tree shows the following information: An ...

  9. SQL 调优专题总结

    oracle 的优化器: oracle 有两种优化器:基于规则的优化器(rbo/rule based optimizer)和基于代价的优化器(cbo/cost based optimizer). 有时 ...

  10. 10 database tables

    本章提要-----------------------------------各种数据库表的讨论, 并介绍什么情况使用哪种表情调表的物理存储特征---------------------------- ...