KMP

我似乎复杂度写的不对。。。

因为位置相同只算一次,后缀数组什么的都不管用了,我们就暴力kmp,但是我写的是暴力跳。。。竟然过了。。。我写bzoj3670才发现。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
int n, k, ans;
int nxt[N];
char s[N];
void kmp(char *s, int len, int *nxt)
{
for(int i = , j = ; i <= len; ++ i)
{
while(s[j + ] != s[i] && j) j = nxt[j];
if(s[j + ] == s[i]) ++ j;
nxt[i] = j;
}
}
int main()
{
scanf("%s%d", s + , &k);
n = strlen(s + );
for(int i = ; i <= n; ++i)
{
char t[N];
int len = ;
for(int j = i; j <= n; ++j) t[++ len] = s[j];
kmp(t, len, nxt);
for(int j = i; j <= n; ++j)
{
int p = j - i + ;
while(p * >= j - i + && p >= k) p = nxt[p];
if(p * < j - i + && p >= k) ++ ans;
}
}
printf("%d\n", ans);
return ;
}

最新文章

  1. jquery写的ajax
  2. 黄聪:使用srvany.exe将任何程序作为Windows服务运行
  3. pthread_cond_wait的原子性
  4. lumen 登陆 注册 demo
  5. centOS安装Mysql指南
  6. 已知ip地址和其子网掩码如何求网络号子网号主机号
  7. 【剑指offer】堆栈推弹出序列
  8. cocoapods管理以及常遇到的问题
  9. 网络流二十四题之P2764 最小路径覆盖问题
  10. layui layui.open弹窗后按enter键不停弹窗问题的解决
  11. ELK日志监控平台安装部署简介--Elasticsearch安装部署
  12. 缺省源和 Vim 配置
  13. servelet基础
  14. Ubuntu系统下安装免驱动摄像头
  15. Android系统更新防互刷功能实现与分析【转】
  16. 20155229《网络对抗技术》Exp5:MSF基础应用
  17. 【LeetCode OJ】Swap Nodes in Pairs
  18. css3整理--rgba
  19. runtime error (运行时错误)
  20. hdu 4686 Arc of Dream(矩阵快速幂)

热门文章

  1. poj 3683 2-sat问题,输出任意一组可行解
  2. spring几种依赖注入方式以及ref-local/bean,factory-bean,factory-method区别联系
  3. msp430项目编程23
  4. poj1376 bfs,机器人
  5. css三大特性
  6. [RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS
  7. SDUTOJ 2475 Power Strings
  8. vue自定义轮播图组件 swiper
  9. 数据库分表和分库的原理及基于thinkPHP的实现方法
  10. Java设计模式-设计模式的六种原则