poj 2185
http://poj.org/problem?id=2185
题意:求最小的模式块,使其无限扩展后包含给你的矩阵块(看别人题解才懂的题意);
分析:假设存在一个模式块可以满足上述条件,那么必然存在一个起点在(0,0)的模式块满足上述条件;
对于每一行,我们找出所有可以满足条件的前缀记录下长度,那么满足所有行的最短的长度就是该模式块的宽r;
对于模式块的长,我们把宽r的字符串压缩看出一个字符,然后再进行KMP,找出该字符串的最小循环串,即长l;
答案就是r * l;
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const int N = +;
int f[N];
void getFail(char *s,int f[]) {
int m = strlen(s);
f[] = -;
for (int i = ; i < m; i++) {
int j = f[i-];
while (j != - && s[j+] != s[i]) j = f[j];
if (s[j+] == s[i]) j++;
f[i] = j;
}
// for (int i = 0; i < m; i++) cout<<f[i]<<" ";cout<<endl;
}
int n,m;
char mz[N][];
int cnt[N];
int check(char *s,int x) {
int j = ;
for (int i = ; i < m; i++) {
if (s[i] != s[j]) return ;
j++;
if (j > x) j = ;
}
return ;
}
void solve(int r){
f[] = -;
for (int i = ; i < n; i++) {
int j = f[i-];
while (j != - && strcmp(mz[j+],mz[i])) j = f[j];
if (strcmp(mz[j+],mz[i]) == ) j++;
f[i] = j;
}
// for (int i = 0; i < n; i++) cout<<f[i]<<" ";cout<<endl;
printf("%d\n",(n - - f[n-]) * (r));
}
int main(){
// getFail("ababab",f);
while (~scanf("%d%d",&n,&m)) {
memset(cnt,,sizeof(cnt)); for (int i = ; i < n; i++) {
scanf("%s",mz[i]);
getFail(mz[i],f);
int j = m-;
while (j != -) {
// cout<<m - 1 - f[j]<<endl;
cnt[m - - f[j]]++;
j = f[j];
}
}
int r = ;
for (int i = ; i <= m; i++) if (cnt[i] == n) {
r = i; break;
}
for (int i = ; i < n; i++) {
mz[i][r] = ;
} solve(r);
}
return ;
}
poj 2185的更多相关文章
- Milking Grid POJ - 2185 || 最小覆盖子串
Milking Grid POJ - 2185 最小覆盖子串: 最小覆盖子串(串尾多一小段时,用前缀覆盖)长度为n-next[n](n-pre[n]),n为串长. 当n%(n-next[n])==0时 ...
- POJ 2185 Milking Grid KMP循环节周期
题目来源:id=2185" target="_blank">POJ 2185 Milking Grid 题意:至少要多少大的子矩阵 能够覆盖全图 比如例子 能够用一 ...
- 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...
- poj 2185 Milking Grid
Milking Grid http://poj.org/problem?id=2185 Time Limit: 3000MS Memory Limit: 65536K Descript ...
- POJ 2185 Milking Grid(KMP最小循环节)
http://poj.org/problem?id=2185 题意: 给出一个r行c列的字符矩阵,求最小的覆盖矩阵可以将原矩阵覆盖,覆盖矩阵不必全用完. 思路: 我对于字符串的最小循环节是这么理解的: ...
- POJ 2185 kmp
题目链接:http://poj.org/problem?id=2185 题意:给出一个R*C(10000 * 75)的矩形字符串,然你求最小的不严格重复矩阵,比如,ABA,最小的重复矩阵是AB,经过复 ...
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- 【KMP】POJ 2185 Milking Grid -- Next函数的应用
题目链接:http://poj.org/problem?id=2185 题目大意:求一个二维的字符串矩阵的最小覆盖子矩阵,即这个最小覆盖子矩阵在二维空间上不断翻倍后能覆盖原始矩阵. 题目分析:next ...
随机推荐
- How to: Provide Credentials for the Dashboards Module when Using External Data Sources
XAF中使用dashboard模块时,如果使用了sql数据源,可以使用此方法提供连接信息 https://www.devexpress.com/Support/Center/Question/Deta ...
- Jmeter接口测试(八)cookie设置
HTTP Cookie 管理器 如果你有一个 HTTP 请求,其返回结果里包含一个 cookie,那么 使用 JmeterCookie 管理器会自动将该 cookie保存起来,而且以后所有对该网站的请 ...
- mnist手写数字识别(决策树)
import numpy as np from sklearn.neural_network import MLPClassifier from sklearn.linear_model import ...
- RabbitMQ入门:路由(Routing)
在上一篇博客<RabbitMQ入门:发布/订阅(Publish/Subscribe)>中,我们认识了fanout类型的exchange,它是一种通过广播方式发送消息的路由器,所有和exch ...
- Spring AOP 报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXXX' defined in class path resource..........
完整报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'befo ...
- 高可用OpenStack(Queen版)集群-10.Nova计算节点
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- Git常用使用技巧
- 此随笔不是使用教材,使用教材参照git官方文档和相应博客 - 此随笔不是转载而来,涉及不少三方链接,再次表示感谢 - 此随便乃实践中碰到的问题,增加开发效率,干货满满 git 撤销某次提交的技巧: ...
- DockerCon2017前瞻 - Docker企业版体验
DockerCon 2017将于四月17号在美国Austin召开.在去年DockerCon上,Docker公司一系列的发布吹响了进军企业市场的号角.今天,容器技术已经愈发成熟,被越来越多的企业所关注和 ...
- 服务端模版注入漏洞检测payload整理
服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...
- 互评Beta版本——二次元梦之队——“I Do”
基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题 (1)N(Need,需求) 这是一款可以教学新手入门编程的软件,不断的通关让他们慢慢学会编程,可以让没有接触过编程的人了 ...