未理解透,鬼知道怎么A的

蒟蒻交了个乱猜贪心搞了10pts,一翻题解群佬乱舞,最后DP解决

$\exists i - next[i] <= j, f[j] = f[next[i]] $

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 500007; char str[N];
int nxt[N];
int f[N], pos[N];
int main(){
//FileOpen();
scanf("%s",str + 1);
int len = strlen(str + 1); nxt[0] = -1;
int j = 0;
R(i,2,len){
while(j != -1 && str[j + 1] != str[i]) j = nxt[j];
nxt[i] = ++j;
} f[1] = 1;
j = 0;
R(i,2,len){
f[i] = i;
if(pos[f[nxt[i]]] >= i - nxt[i]) f[i] = f[nxt[i]];
pos[f[i]] = i;
} printf("%d", f[len]);
return 0;
}

Luogu3426 [POI2005]SZA-Template (KMP)(未完成)的更多相关文章

  1. 2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP)

    2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP) https://www.luogu.com.cn/problem/P3426 题意: 你打算在纸上印一串字 ...

  2. luogu3426 [POI2005]SZA-Template 后缀树

    链接 bzoj不能auto https://www.luogu.org/problemnew/show/P3426 思路 这个要求的串一定是S的前缀和S的后缀. 转化一下 建立出来fail树(fail ...

  3. [Freemarker] Getting Start

    Freemarker是一个模板引擎,在.NET中有类似的T4模板,FreeMarker对ASP.NET MVC也很友好,链接地址,引用官方的一幅图 模板+数据=视图 Following are the ...

  4. 2018 noip 备战日志

    我是写给自己看的…… Day1 10.8 今天开始停晚修课了,开始认真备战考试了. 今天晚上效率不错,竟然不会累,应该是平时一直这个时间写作业大脑高度集中, 现在换了编程也一样可以集中到这个状态 一些 ...

  5. BZOJ.1535.[POI2005]SZA-Template(KMP DP)

    BZOJ 洛谷 \(Description\) 给定一个字符串\(s\),求一个最短的字符串\(t\)满足,将\(t\)拼接多次后,可以得到\(s\).拼接是指,可以将\(t\)放在当前串的任意位置, ...

  6. BZOJ 1355 & KMP

    BZOJ放这种丝帛我也是醉了... 不过来填一下求最小循环节的坑... 以这道题为例,相同文本串粘起来的串中取一小节,可以把任意一个字符看做文本串头. 那么我们一次KMP求出next函数然后显见,最后 ...

  7. HDU 1686 & KMP

    题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 … ...

  8. hdu 5769 Substring 后缀数组 + KMP

    http://acm.hdu.edu.cn/showproblem.php?pid=5769 题意:在S串中找出X串出现的不同子串的数目? 其中1 <= |S| < $10^5$ 官方题解 ...

  9. HDU-4749 Parade Show KMP算法 | DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题意:给两个串S和P,求S串中存在多少个与P串的大小关系一样的串. 因为数字的范围是1<= ...

随机推荐

  1. Spring-Cloud-Alibaba系列教程(一)Nacos初识

    前言 在2020年即将开启SpringCloudAlibaba的专题,希望2020年共同学习进步. 学习资料 文档 Naco文档 程序猿DD Spring Cloud Aliabab专题 专题博客 视 ...

  2. Java 基础常见知识点&面试题总结(中),2022 最新版!| JavaGuide

    你好,我是 Guide.秋招即将到来,我对 JavaGuide 的内容进行了重构完善,公众号同步一下最新更新,希望能够帮助你. 上篇:Java 基础常见知识点&面试题总结(上),2022 最新 ...

  3. 技术分享 | app自动化测试(Android)--App 控件交互

    原文链接 常用操作 点击操作 通常获取到元素之后,可以调用 click() 方法来实现对这个元素的点击操作.示例代码如下: python 版本 driver.find_element_by_id(&q ...

  4. SQL Server默认数据库存放位置

    更新记录 2022年6月13日 发布. Windows操作系统 C:\Program Files\Microsoft SQL Server\MSSQLxx_xx.MSSQLSERVER\MSSQL\D ...

  5. 慢到不能忍?别忍了,Ubuntu 21.10 APT 源修改为华为云镜像源

    更新记录 2022年4月15日:本文迁移自Panda666原博客,原发布时间:2021年3月29日. 2022年4月15日:将源改为华为云,华为云更方便.Ubuntu从20.04更新到21.10. 切 ...

  6. wappalyzer 上各种开源框架功能

    Underscore.js  官网地址:https://underscorejs.org/     一个JavaScript实用库,提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScrip ...

  7. node开启 https线上服务你不会吗?

    var https=require("https");//https服务var fs = require("fs")var express = require( ...

  8. SprinigBoot自定义Starter

    自定义Starter 是什么 starter可以理解是一组封装好的依赖包,包含需要的组件和组件所需的依赖包,使得使用者不需要再关注组件的依赖问题 所以一个staerter包含 提供一个autoconf ...

  9. PoweJob高级特性-MapReduce完整示例

    由于网上搜索 PowerJob MapReduce 都是设计原理,demo也展示个空壳子,没有演示Map到Reduce结果怎么传递,对于没有MR开发经验的人来说并没有什么帮助,所以这里写了一个有完整计 ...

  10. HashSet存储自定义类型元素和LinkedHashSet集合

    HashSet集合存储自定义类型元素 HashSet存储自定义类型元素 set集合报错元素唯一: ~存储的元素(String,Integer,-Student,Person-)必须重写hashCode ...