POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)
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;
代码:
1 #include<iostream>
2 #include<cstring>
3 #include<cstdlib>
4 #include<cstdio>
5 #include<algorithm>
6 using namespace std;
7 const int row =10050;
8 const int cow =80;
9 char str[row][cow];
10 int next[row][cow];
11 int RR,CC;
12 int main()
13 {
14 while(scanf("%d%d",&RR,&CC)!=EOF)
15 {
16 for(int i=0;i<RR;i++)
17 scanf("%s",str[i]);
18 int i,j,k;
19 //先求出每一行的next
20 int max_row=-1;
21 for(k=0;k<RR;k++)
22 {
23 i=0; j=-1;
24 next[k][0]=-1;
25 while(i<CC)
26 {
27 if(j==-1||str[k][i]==str[k][j])
28 {
29 i++;
30 j++;
31 next[k][i]=j;
32 }
33 else j=next[k][j];
34 }
35 if(max_row<(CC-next[k][CC]))
36 max_row=(CC-next[k][CC]);
37 }
38 int max_cow=-1;
39 //求出所有列中的最小循环节
40 for(k=0;k<CC;k++)
41 {
42 i=0;
43 j=-1;
44 next[0][k]=-1;
45 while(i<RR)
46 {
47 if(j==-1||str[i][k]==str[j][k])
48 {
49 i++;
50 j++;
51 next[i][k]=j;
52 }
53 else
54 j=next[j][k];
55 }
56 if(max_cow<(RR-next[RR][k]))
57 max_cow=(RR-next[RR][k]);
58 }
59 printf("%dn",max_row*max_cow);
60 }
61 return 0;
62 }
- Solidity语法知识点(文末有彩蛋)
- 人脸Haar特征与快速计算神器:积分图
- 内存为王:DBIM RAC Share Nothing架构的挑战和解决方案
- 调用finecms栏目多图怎么实现
- phpcms调用子栏目名称/文章怎么操作
- 小程序开发工具全新上线 附下载地址和教程
- JS页面跳转代码怎么写?总结了5种方法
- finecms如何控制调用子栏目的数量
- finecms如何调用多个指定栏目的内容
- finecms同时调用子栏目和子栏目的文章怎么操作
- 群体智能算法-黏菌寻找食物最优路线行为模拟 2
- thinkcmf安装教程与目录结构详解 快速上手版
- finecms如何批量替换文章中的关键词?
- dedecms批量修改文章为待审核稿件怎么操作
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- yii2实现Ueditor百度编辑器的示例代码
- PHP下载文件函数与用法示例
- php实现银联商务公众号+服务窗支付的示例代码
- php使用json-schema模块实现json校验示例
- 17个品牌,113款5G手机,5G离我们越来越近。
- PHP的cookie与session原理及用法详解
- Thinkphp5.0框架视图view的循环标签用法示例
- Thinkphp5.0 框架视图view的比较标签用法分析
- laravel 操作数据库常用函数的返回值方法
- laravel 验证错误信息到 blade模板的方法
- thinkPHP+LayUI 流加载实现功能
- Thinkphp5.0框架使用模型Model的获取器、修改器、软删除数据操作示例
- laravel5.2表单验证,并显示错误信息的实例
- ThinkPHP 5.1 跨域配置方法
- PHP调用接口API封装的例子