题意

题目链接

给出\(m\)个长度为\(n\)的排列,问有多少连续公共子串

\(m \leqslant 10, n \leqslant 10^5\)

Sol

非常naive的一道题然而交了3遍才过(昨晚真的困得不行。。)

枚举第一个串的位置,直接维护10个指针,分别表示每个串与第一个串匹配到的位置,同时记录出已经匹配了多少位

因为题目中给出的是排列,所以如果某一位不能匹配了,则需要从新的位置开始

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define ull unsigned long long
#define rg register
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e5 + 10, INF = 1e9 + 10, mod = 998244353;
const double eps = 1e-9;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M;
int a[11][MAXN], pos[11][MAXN], now[MAXN], len[MAXN];
main() {
N = read(); M = read();
for(int i = 1; i <= M; i++)
for(int j = 1; j <= N; j++) {
a[i][j] = read();
pos[i][a[i][j]] = j;
}
LL ans = 0;
for(int i = 1; i <= N; i++) {
len[1] = i;
for(int j = 2; j <= M; j++) {
if(a[j][now[j] + 1] != a[1][i]) now[j] = pos[j][a[1][i]], len[j] = 1;
else now[j]++, len[j]++;
}
LL mn = INF;
for(int j = 1; j <= M; j++) mn = min(mn, (LL)len[j]);
ans += mn;
}
cout << ans;
return 0;
} /*
*/

最新文章

  1. ASIHttpRequest 使用理解
  2. android 调用地图
  3. c# 靠谱的bitmap转byte[]
  4. VS2012网布网站与IIS配置
  5. @JsonFormat时间不对
  6. poj2411(状压dp)
  7. strip 使用命令
  8. 转 Goldengate常用命令
  9. 在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题
  10. npm-package.json
  11. mui框架下监听返回按钮
  12. Unity 获取指定资源目录下的所有文件
  13. 数组Array的一些方法
  14. C# dynamic类型报错:“object”不包含“xxx”的定义
  15. React Native中的约束规范
  16. python中url解析 or url的base64编码
  17. POJ1015陪审团(Jury Compromise)——dp+路径记录
  18. POJ - 3254 Corn Fields(状压DP)题解
  19. MySQL与PHP的连接教程步骤(图文)
  20. 【UVa】And Then There Was One(dp)

热门文章

  1. Oracle 第三方管理工具整理
  2. 4G模块在AM335x上的移植
  3. Python爬虫:微博粉丝列表
  4. BAE+Python+Django+Wechatpy+Baidu weather api +微信订阅号 = 实现微信查询天气
  5. selenium自动化测试用例需要关注的几点(二)
  6. sqlplus column命令用法
  7. 以cmd命令行方式执行php文件时,传递参数
  8. jquery清空下拉框,保留第一个
  9. HTTP协议(一):介绍
  10. Ajax介绍及爬取哔哩哔哩番剧索引追番人数排行