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 }
- 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 数组属性和方法
- C++下shm共享内存模块
- 基于TypeScript封装Axios笔记(九)
- springmvc之SessionAttributes注解所引发的异常
- 【tensorflow2.0】处理文本数据-imdb数据
- springmvc之异常处理DefaultHandlerExceptionResolver
- springmvc之返回json类型的数据给前端
- springmvc之mvc:view-controller标签设置可以直接访问的视图
- exec族
- springmvc实例之添加雇员相关信息(二)
- Qt引入第三方库(亲测Qt4和Qt5)
- springmvc之与spring进行整合
- recv&send函数
- setsockopt与getsockopt
- django-模型之(ORM)对象关系映射(一)
- Mybatis学习笔记(二)Mapper的配置问题