poj 3461 kmp算法
来源:互联网 发布:eclipse怎么编写java 编辑:程序博客网 时间:2024/05/16 12:31
首先说这个题目的意思,就是去匹配然后找出最多能够匹配的次数
这个题一开始直接暴力没有过,就感觉这应该是我没有接触过的算法,训练赛结束后去学习,知道了关于字符串的kmp算法,说实话对于这个算法了解还不够很详细,
先学习了这个板子,以我现在的水平去了解这个算法有点难度,关于字符串的那个覆盖问题,有点难以理解,以后了解更多会回来再更这一篇博客的
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <math.h>#include <stack>#define LL long longusing namespace std;const int maxn = 100000 + 10;int next[maxn];const int INF = 0x3f3f3f3f;int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};char s[maxn*10],p[maxn];int lens,lenp;void getnext(){ int i = 0,j = -1; next[0] = -1; while(i != lenp) { if(j == -1 || s[i] == s[j]) next[++i] = ++j; else j = next[j]; }}int kmp(){ int i = 0,j = 0,count = 0; while(i != lens && j != lenp) { if(s[i] == p[j] || j == -1) ++i,++j; else j = next[j]; if(j == lenp) { count++; j = next[j]; } } return count;}int main(){ int ncase; int len; int ans; cin>>ncase; while(ncase--) { scanf("%s%s",p,s); lens = strlen(s); lenp = strlen(p); getnext(); ans = kmp(); printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ 3461 KMP算法
- poj 3461 kmp算法
- poj 3461 Oulipo KMP算法
- poj 3461 Oulipo KMP算法
- POJ 3461和COJ 1248 KMP算法
- Poj 3461 Oulipo(KMP算法)
- POJ 3461 Oulipo (KMP算法)
- POJ 3461 Oulipo KMP算法题解
- poj 3461 Oulipo(KMP 字符串匹配算法)
- kmp算法(POJ 3461 Oulipo)
- KMP算法——POJ 3461
- POJ 3461 : Qualification - 字符串匹配,KMP算法
- poj 3461 Oulipo 字符串匹配 KMP算法
- POJ 3461&& hiho1015 Oulipo [KMP算法]
- KMP算法 学习例题 POJ 3461Oulipo
- poj 2752 kmp算法
- poj 2406 KMP算法
- poj 4468Spy(kmp算法)
- 浙大PAT甲级-1029
- grunt官网教程(中文版)
- Android之CardView的使用
- 详解Response、Request二
- 将数组写入txt读出后数据出错
- poj 3461 kmp算法
- 代理模式
- SpringBoot(七):SpringBoot整合Swagger2
- 1057. 数零壹(20)
- 并发AQS同步器
- TCP/IP协议之IP协议
- POJ3159 最大差距(差分约束系统) (K)
- PAT b1031-b1035题解
- CentOS_6.5下安装tomcat-7.0.69