Milking Grid
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 8226   Accepted: 3549

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


题意:在N*M字符矩阵中找出一个最小子矩阵,使其多次复制所得的矩阵包含原矩阵。N<=10000,M<=75


只需要一行做一个字母求一次,再一列做一个字母求一次就好了,然后和子串是一样的n-fail[n]

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e4+,M=;
int n,m,k,fail[N];
char s[N][M];
bool cmp1(int a,int b){
for(int i=;i<=m;i++) if(s[a][i]!=s[b][i]) return false;
return true;
}
bool cmp2(int a,int b){
for(int i=;i<=k;i++) if(s[i][a]!=s[i][b]) return false;
return true;
}
void getFail(int n,bool (*cmp)(int a,int b)){
fail[]=;
for(int i=;i<=n;i++){
int j=fail[i-];
while(j&&!cmp(j+,i)) j=fail[j];
fail[i]=cmp(j+,i)?j+:;
}
} int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%s",s[i]+);
getFail(n,cmp1);
k=n-fail[n];
memset(fail,,sizeof(fail));
getFail(m,cmp2);
printf("%d",k*(m-fail[m]));
}
 

POJ 2185 Milking Grid [KMP]的更多相关文章

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

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

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

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

  3. [poj 2185] Milking Grid 解题报告(KMP+最小循环节)

    题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...

  4. POJ 2185 Milking Grid(KMP)

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4738   Accepted: 1978 Desc ...

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

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

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

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

  7. poj 2185 Milking Grid

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

  8. Poj 2165 Milking Grid(kmp)

    Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, ...

  9. POJ 2185 Milking Grid (KMP,求最小覆盖子矩阵,好题)

    题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接:http://poj.org/showmessage?message_id=153 ...

随机推荐

  1. 用于浏览器桌面通知的Web API 接口 -notification

    notification 接口用于浏览器向用户提供通知内容:常见的如网页版的微信: 1.实现,需要Notifications API 提供的通知接口: 用法: let notification = n ...

  2. 20170723-Ioc与AOP

    Ioc与AOP 功能.语法.分类.原理.例子.补充(AOP-Ioc-DI) 1.AOP: ①功能体现:是拦截,过滤器: ②相关语法:借助特性语法作为切入点: ③实现方式分类:动态代理+静态织入: ④实 ...

  3. springcloud干活之服务消费者(feign)

    springcloud系列文章的第三篇 本章将继续讲述springcloud的消费者(feign) Spring Cloud Feign是一套基于Netflix Feign实现的声明式服务调用客户端. ...

  4. 关于Vue的各个UI框架(elementUI、mint-ui、VUX)

    elementUI 官网:http://element.eleme.io/ 使用步骤: 1.安装完vue-cli后,再安装 element-ui 命令行:npm i element-ui -D 相当于 ...

  5. dede 提交表单 发送邮件

    第一步:要到dede后台设置好邮箱的资料,并且确定所用的邮箱开启了smtp 第二步:找到/plus/diy.php在 [cce]$query = "INSERT INTO `{$diy-&g ...

  6. 关于MacOS升级10.13系统eclipse菜单灰色无法使用解决方案

    最近,苹果发布了macOS High Sierra,版本为10.13,专门针对mac pro的用户来着,至于好处大家到苹果官网看便是,我就是一个升级新版本系统的受益者,同时也变成了一个受害者:打开ec ...

  7. Android 双卡获取当前使用流量在线卡的信息

    最近接触了一个项目,需要获取在线流量卡的信息,下面的方式,可以获取大部分手机的正确手机卡信息. 一  获取获取IMEI public static String getDeviced(int solt ...

  8. 百度Apollo 尝试

    从Git-Hub上下载了Apollo源码在Ubuntu上准备运行一下 完成了以下步骤: bash docker/scripts/install_docker.sh bash docker/script ...

  9. 三十天学不会TCP,UDP/IP网络编程 - UDP的实践--DHCP

    在经历了一顿忙碌加出去玩了玩之后,我又开始重新更新了~这是最新的一篇~完整版可以去gitbook(https://www.gitbook.com/@rogerzhu/)看到,在gitbook的后台流量 ...

  10. WebSphere--定制配置

    本节介绍如何启动和使用 WebSphere应用服务器的管理器(一个图形界面)为 Servlet 活动和 WebSphere应用服务器的组件定制基本设置参数.    1.启动 WebSphere应用服务 ...