[HDU 3336]Count the String[kmp]
来源:互联网 发布:sql server 2005 iis 编辑:程序博客网 时间:2024/05/21 10:32
题意:
给出一个字符串,求其所有前缀串为模式串时匹配成功的次数.
思路:
就和AC自动机那题处理模式串重叠的方法一样,每到一处,回溯到根检查一遍.
#include <cstdio>using namespace std;const int MAXW = 200005;const int MOD = 10007;char W[MAXW];int n;int next[MAXW];void prekmp(char *B, int *next){ int j = -1; next[0] = -1; for(int i=1; B[i]; i++) { while(j != -1 && B[j+1] != B[i]) j = next[j]; if(B[i] == B[j+1]) j++; next[i] = j; } /*for(int i=0;i<n;i++) printf("next[%d] %d\n",i,next[i]);*/}int kmp(char *B, int *next){ long long ret = 0; for(int i=0; B[i]; i++) { ret++; int tmp = next[i]; while(tmp!=-1) { ret++; tmp = next[tmp]; } ret %= MOD; } return ret;}int main(){ int cas; scanf("%d",&cas); while(cas--) { scanf("%d",&n); scanf("%s",W); prekmp(W,next); printf("%d\n",kmp(W,next)); }}
- hdu 3336 Count the string KMP
- KMP Hdu-3336 Count the string
- HDU 3336 Count the string(KMP 理解)
- HDU 3336 Count the string KMP
- HDU 3336 Count the string(KMP+dp)
- [HDU 3336]Count the String[kmp]
- [HDU 3336]Count the String[kmp][DP]
- HDU 3336 Count the string KMP+DP
- hdu 3336 Count the string(KMP)
- hdu 3336 Count the string KMP+DP
- HDU 3336 Count the string(KMP)
- hdu 3336 Count the string(KMP)
- hdu 3336 Count the string(KMP)
- HDU 3336 Count the string / KMP
- HDU 3336 Count the string kmp+dp
- 【HDU】3336 Count the string KMP
- hdu 3336 Count the string(KMP)
- hdu -- 3336 Count the string(KMP + dp)
- 一个自动代理的php实现
- 原型设计模式
- ASP.NET MVC4 PRG模式
- 本地文件同步——C#源代码
- 实习第三天 delphi学习
- [HDU 3336]Count the String[kmp]
- Case用法
- Where Should the Bugs Be Fixed? 导读
- Android系统信息获取 之八:WIFI设备和WIFI信号信息获取
- 20130429-泰山小记
- 安卓Fragment的用法
- 项目总结----sql数据库使用总结
- eclipse常用快捷键
- C基础:结构体