POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 6169 | Accepted: 2573 |
Description
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
* 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
Sample Input
2 5
ABABA
ABABA
Sample Output
2
Hint
Source
#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)的更多相关文章
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- 依据矩阵的二维相关系数进行OCR识别
我想通过简单的模板匹配来进行图像识别. 把预处理好的字符图片,分别与A到Z的样本图片进行模板匹配. 结果最大的表明相关性最大,就能够识别字符图片了. 在实际应用中.我用了openCV的matchTem ...
- 牛客练习赛1 矩阵 字符串二维hash+二分
题目 https://ac.nowcoder.com/acm/contest/2?&headNav=www#question 解析 我们对矩阵进行二维hash,所以每个子矩阵都有一个额hash ...
- 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都依照从左到右的递增的顺序排序,输入这种一个数组和一个数,推断数组中是否包括这个数
// 二维数组中的查找,杨氏矩阵在一个二维数组中.每行都依照从左到右的递增的顺序排序. // 每列都依照从上到下递增的顺序排序.请完毕一个函数,输入这种一个数组和一个数.推断数组中是否包括这个数 #i ...
- 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...
- POJ 2185 Milking Grid KMP(矩阵循环节)
Milking Grid Time Limit: 3000MS Memory Lim ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
随机推荐
- [转]Unity3D:Gizmos画圆(原创)
using UnityEngine; using System; public class HeGizmosCircle : MonoBehaviour { public Transform m_Tr ...
- 详解CreateProcess调用内核创建进程的过程
昨天同学接到了腾讯的电面,有一题问到了CreateProcess创建进程的具体实现过程,他答得不怎么好吧应该是, 为了以防万一,也为了深入学习一下,今天我翻阅了好多资料,整理了一下,写篇博客,也算是加 ...
- jquery之 css()方法。用法类似的有attr(),prop(),val()
[注]attr(),prop(),val()的用法结构和css()一致,可参考 css()函数用于设置或返回当前jQuery对象所匹配的元素的css样式属性值. 该函数属于jQuery对象(实例).如 ...
- Create Hierarchical Tree To Control Records In Oracle Forms
Download Source Code Providing an example form for creating hierarchical trees in Oracle Forms to co ...
- android测试参考,及CreateProcess failure, error问题解决
今天小伙伴问我问题,我给了这2个小命令,或许做android测试的同学可以用得着. 截图命令adb shell /system/bin/screencap -p /sdcard/screenshot. ...
- Android中利用SharedPreferences保存信息
package com.example.sharepreferen; import android.content.Context; import android.content.SharedPref ...
- NS3 日志(Logging)、命令行参数、Tracing系统概述(转载)
NS-3日志子系统的提供了各种查看仿真结果的渠道: 一.使用Logging Module 1 [预备知识]日志级别及其对应的宏 NS-3 提供了若干个日志级别来满足不同的 Debug 需求,每一级的日 ...
- iOS - Swift NSKeyedArchiver 数据归档
前言 public class NSKeyedArchiver : NSCoder public class NSKeyedUnarchiver : NSCoder 在 OC 语言中,归档是一个过程, ...
- Redis基础知识之————如何处理客户端连接
redis 连接建立 Redis Redis 通过监听一个 TCP 端口或者 Unix socket 的方式来接收来自客户端的连接,当一个连接建立后,Redis 内部会进行以下一些操作: 首先,客户端 ...
- 关于JAVA中URL传递中文参数,取值是乱码的解决办法
前几天看到有网友在问URLDecoder和URLEncoder方面的使用问题,突然想起,原来我刚遇到这两个类时,也觉得很神密,由此可以想想初学者的心情,于是便有了今天的这篇文章. 其实,这两个类的使用 ...