kmp
infinity°º
stay hungry stay foolish
展开
-
hdu1686套模板
可重复 #include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; char a[maxn],b[maxn]; int nex[maxn]; int n,m; void pre(){ nex[1]=0; int i,j=0; for(i=1;i<m;i++){ while(j>0&&b[i+1]!=b[j+1]) j=nex.原创 2021-08-13 21:32:53 · 60 阅读 · 0 评论 -
hdu3746还是循环节题目。模板都差不多,记住模板对应题型就挺好写的
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+7; char a[maxn],b[maxn]; int nex[maxn]; int n,m; void pre(){ nex[1]=0; int i,j=0; for(i=1;i<m;i++){ while(j>0&&b[i+1]!=b[j+1]) j=nex[j]; .原创 2021-08-13 21:22:29 · 64 阅读 · 0 评论 -
hdu1711
读入的串之间有空格,不能用char型数组,用%d读入存入int型数组 #include<bits/stdc++.h> using namespace std; const int maxn=1e6+7; int a[maxn],b[maxn]; int nex[maxn]; int n,m; void pre(){ nex[1]=0; int i,j=0; for(i=1;i<m;i++){ while(j>0&&b[i+.原创 2021-08-13 20:57:06 · 52 阅读 · 0 评论 -
hdu1358 通过pre求循环节
果然 还是踩了老!!!,一不留神把nex定义成char了!!!! #include<bits/stdc++.h> using namespace std; const int maxn=1e6+7; char b[maxn]; int nex[maxn]; int m; void pre(){ nex[1]=0; int i,j=0; for(i=1;i<m;i++){ while(j>0&&b[i+1]!=b[j+1])原创 2021-08-13 20:37:47 · 66 阅读 · 0 评论 -
hdu3336
预处理b串 实质是求b串的前缀 和 后缀 的最大相同长度。 #include<bits/stdc++.h> using namespace std; const int maxn=2e5+5; const int mod=1e4+7; char b[maxn],nex[maxn]; int m; void pre(){ nex[1]=0; int i,j=0; for(i=1;i<m;i++){ while(j>0&&b[i+1]!=b[j+1]) .原创 2021-08-13 17:26:48 · 48 阅读 · 0 评论 -
hdu2087kmp,pre函数 隔段时间复习下
#include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; char a[maxn],b[maxn],nex[maxn]; int n,m; //由b串 预处理nex数组 void pre(){ nex[1]=0; int i,j=0;//i j要错位,因为是在同一个字符串内 for(i=1;i<m;i++){ while(j>0&&b[i+1]!=b[j+1]) j=ne.原创 2021-08-13 15:46:56 · 74 阅读 · 0 评论