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. 【转载】COM多线程原理与应用

    原文:COM多线程原理与应用 目录: COM多线程原理与应用 目录: 前言: 套间: 套间的定义: 套间的分类: 套间的进入和退出: 对象的同步: 组件对象的同步: COM对象线程模型: 进程内对象线 ...

  2. Calling / Running a report in Oracle forms 10g / 11g

    Calling / Running a report in Oracle forms 10g / 11g Below is the procedure to call a report in Orac ...

  3. spring引入实体类映射文件

    由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好  LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件:  mapp ...

  4. 程序间数据共享与传递:EXPORT/IMPORT、SAP/ABAP Memory

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

  5. CUBRID学习笔记 45 REPLACE DELETE MERGE 教程

    c#,net,cubrid,教程,学习,笔记欢迎转载 ,转载时请保留作者信息.本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com . 过错 ------ 官方文档是英文的, ...

  6. cocos2d-x 3.X (二)创建动起来的精灵

    [参考文章]http://www.cnblogs.com/suguoqiang/archive/2013/04/03/2997316.html 在HelloWorldScene.h中声明void ro ...

  7. 阿里云大数据三次技术突围:Greenplum、Hadoop和“飞天”

    阿里云大数据三次技术突围:Greenplum.Hadoop和"飞天"    对于企业来说,到底什么是云计算?相信很多企业都有这样的困惑,让我们一起回到这个原始的起点探讨究竟什么是云 ...

  8. JSON学习总结

    最近几天使用json的需求比较急迫,所以学习了一下json.此文仅当笔记,以防忘却. 此文主要分为js和java总结: 先介绍json格式: JSON 数据的书写格式是:名称/值对. ***:可以更容 ...

  9. [LED]如何配置LCD背光和LED,调试方法

    [DESCRIPTION] 如何配置LCD背光和LED,调试方法 [SOLUTION]LCD背光和LED配置文件alps/custom/<proj name>lk/cust_leds.ca ...

  10. for循环与for in循环

    json是js里的一种数据格式.var obj={a:15,b:8,c:12} json数组对象 var arr=[15,8,12]; 数组alert(obj.a); ---15alert(obj[' ...