P1659 [国家集训队]拉拉队排练
思路
求出cnt和len之后,直接乘起来即可
代码
#include <cstdio>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
int Nodecnt,last,n,k;
signed trans[1001000][26],fail[1001000];
struct Node{
signed len,cnt;
bool operator < (const Node &b) const{
return len>b.len;
}
}a[1001000];
char s[1001000];
const int MOD = 19930726;
int pow(int a,int b){
int ans=1;
while(b){
if(b&1)
ans=(1LL*ans*a)%MOD;
a=(1LL*a*a)%MOD;
b>>=1;
}
return ans;
}
int New_state(int _len){
a[Nodecnt].len=_len;
return Nodecnt++;
}
int get_fail(int p,int n){
while(s[n]!=s[n-a[p].len-1])
p=fail[p];
return p;
}
void insert(int n){
int cur=get_fail(last,n);
if(!trans[cur][s[n]]){
int t=New_state(a[cur].len+2);
fail[t]=trans[get_fail(fail[cur],n)][s[n]];
trans[cur][s[n]]=t;
}
a[trans[cur][s[n]]].cnt++;
last=trans[cur][s[n]];
}
signed main(){
// freopen("test.in","r",stdin);
int ans=1;
scanf("%lld %lld",&n,&k);
scanf("%s",s+1);
s[0]=-1;
New_state(0);
fail[0]=1;
New_state(-1);
last=0;
for(int i=1;i<=n;i++){
s[i]-='a';
insert(i);
}
for(int i=Nodecnt-1;i>=0;i--)
a[fail[i]].cnt+=a[i].cnt;
sort(a,a+Nodecnt);
for(int i=0;i<Nodecnt&&k>0;i++){
if(a[i].len%2){
ans=(1LL*ans*pow(a[i].len,min(1LL*a[i].cnt,k)))%MOD;
k-=a[i].cnt;
}
}
printf("%lld\n",ans);
return 0;
}
P1659 [国家集训队]拉拉队排练的更多相关文章
- 洛谷 P1659 [国家集训队]拉拉队排练(Manacher)
题目链接:https://www.luogu.com.cn/problem/P1659 思路: 首先跑一遍Manacher,用$cnt_i$记录长为$i$的回文串有多少个. 所记录的$cnt$并不是最 ...
- luogu P1659 [国家集训队]拉拉队排练
唔....话说好久没有发布题解了(手痒痒了 首先特别鸣谢lykkk大佬今天下午教我Manacher算法,甚是感谢 为了体现学习成果,写一篇蒟蒻版的题解(大佬勿喷 言归正传 题面——>在这儿 首先 ...
- Manacher【p1659】 [国家集训队]拉拉队排练
题目描述 n个女生举牌子(只含有26个小写字母,长度为n的字符串), 如果连续的一段女生,有奇数个,并且她们手中的牌子所写的字母,从左到右和从右到左读起来一样,那么这一段女生就被称作和谐小群体. 现在 ...
- 【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)
题目链接 马拉车+简单膜你 #include <cstdio> #include <cstring> #include <algorithm> using name ...
- 题解 P1659 【[国家集训队]拉拉队排练】
一眼可得PAM 如果没学过PAM的可以看这里:PAM学习小结 我们令PAM上多记录一个信息\(sum\),表示该节点表示串在原串上出现了多少次. 当我们处理完了\(sum\),对于长度\(len\)为 ...
- [回文树][BZOJ2160][国家集训队]拉拉队排练
题面 Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长的楚雨荨同学知道,帮助篮 ...
- [国家集训队]拉拉队排练 Manancher_前缀和_快速幂
Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace st ...
- [国家集训队] 拉拉队排练 - Manacher
用 Manacher 跑出回文串长,注意这里不需要偶数长度所以不需要对串做一些奇怪的处理 然后用前缀和搞一下,计算答案时跑快速幂即可 #include <bits/stdc++.h> us ...
- luoguP1659 [国际集训队]拉拉队排练 manacher算法
直接统计长度为$i$的回文子串有多少个 然后倒叙枚举长度,快速幂统计一下即可 复杂度$O(n \log n)$ #include <cstdio> #include <cstring ...
随机推荐
- python基础1 print()函数
一切程序的开始都是由print('hello world') 了解print()函数 输出python之歌 print(''' 优美胜于丑陋明了胜于晦涩简洁胜于复杂复杂胜于凌乱扁平胜于嵌套间隔胜于紧凑 ...
- Alibaba, I'm interested in you.
Working for Alibaba is an aspiration for some. For other it’s the possibility of lucrative stock opt ...
- Java学习--抽象类和接口
https://www.cnblogs.com/dolphin0520/p/3811437.html 抽象类 先了解一下[抽象方法]—一种特殊的方法,只有声明,没有具体的实现 abstract vo ...
- 【托业】【全真题库】TEST2-语法题
105 to do sth 不定时可充当形容词修饰名词 In an effort to reduce prices----为降低价格 106. 修饰比较级:far,much,even,still,a ...
- 2018-2019-2 网络对抗技术 20165236 Exp6 信息搜集与漏洞扫描
2018-2019-2 网络对抗技术 20165236 Exp6 信息搜集与漏洞扫描 一.实验内容 1.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 2.实践内容 (1)各种搜索技巧的应用 ...
- 干了这杯Java之transient关键字
看源码的时候,发现transient这个关键字,不甚理解,查找资料发现:不被序列化 疑问: 静态变量是不是不被序列化? public class User implements Serializabl ...
- log4cplus在VS项目中的使用
log4cplus是C++编写的开源的日志系统,宣称具有线程安全.灵活.以及多粒度控制的特点,通过将日志划分优先级使其可以面向程序调试.运行.测试.和维护等全生命周期.你可以选择将日志输出到屏幕.文件 ...
- AWS 移动推送到iOS设备,Amazon Pinpoint
前言 第一次对接aws,遇到的坑是真多.现在记录一下.本文主要用到的是[Amazon Pinpoint]推送. 开发人员的指南:https://docs.aws.amazon.com/zh_cn/pi ...
- 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(三)
接第二篇写 第四步,测试Oracle数据库的性能. a.加载JDBC Oracle驱动,添加线程组和线程属性和前面两部一样,如果有需要可以往前翻看. b.设置JDBC Connection Oracl ...
- dede织梦手机站m文件夹功能基础详解
织梦2015年6月8日更新后,就添加了很多针对手机移动端的设计,最大的设计就是添加了生成二维码的织梦标签和织梦手机模板功能,织梦更新后,默认的 default模板中就包含手机模板,所以我们可以给织梦网 ...