https://nanti.jisuanke.com/t/31721

题意 n个位置 有几个限制相邻的三个怎么怎么样,直接从3开始 矩阵快速幂进行递推就可以了

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+,maxn=;
struct Matrix
{
ll m[maxn][maxn];
Matrix()
{
memset(m,,sizeof(m));
}
void init()
{
for(int i=; i<maxn; i++)
for(int j=; j<maxn; j++)
m[i][j]=(i==j);
}
Matrix operator +(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
c.m[i][j]=(m[i][j]+b.m[i][j])%mod;
}
}
return c;
}
Matrix operator *(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
for(int k=; k<maxn; k++)
{
c.m[i][j]=(c.m[i][j]+(m[i][k]*b.m[k][j])%mod)%mod;
}
}
}
return c;
}
Matrix operator^(const ll &t)const
{
Matrix ans,a=(*this);
ans.init();
ll n=t;
while(n)
{
if(n&) ans=ans*a;
a=a*a;
n>>=;
}
return ans;
}
};
int xishu[][]={
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,};
int main()
{
int t;
ll n,m,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
if(n==)
{
printf("3\n");
continue;
}
if(n==)
{
printf("9\n");
continue;
}
Matrix temp,aa;
for(int i=;i<maxn;i++)
{
for(int j=;j<maxn;j++)
{
temp.m[i][j]=xishu[i][j];
}
}
for(int i=;i<maxn;i++)
aa.m[i][]=;
temp=temp^(n-);
aa=temp*aa;
ll ans=;
for(int i=;i<maxn;i++)
ans=(ans+aa.m[i][])%mod;
cout<<ans<<endl;
}
return ;
}

https://nanti.jisuanke.com/t/31717

解析 傻逼题,数据范围应该是2e5,真是傻逼,被安排的明明白白。存个后缀自动机的板子。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
typedef long long ll;
char s[maxn];
int len,k,n,m;
char temp[];
struct SAM{
int last,cnt,nxt[maxn*][],fa[maxn*],l[maxn*],num[maxn*];
ll ans;
void init(){
last = cnt=;
memset(nxt[],,sizeof nxt[]);
fa[]=l[]=num[]=;
ans=;
}
int inline newnode(){
cnt++;
memset(nxt[cnt],,sizeof nxt[cnt]);
fa[cnt]=l[cnt]=num[cnt]=;
return cnt;
}
void add(int c){
int p = last;
int np = newnode();
last = np;
l[np] =l[p]+;
while (p&&!nxt[p][c]){
nxt[p][c] = np;
p = fa[p];
}
if (!p){
fa[np] =;
}else{
int q = nxt[p][c];
if (l[q]==l[p]+){
fa[np] =q;
}else{
int nq = newnode();
memcpy(nxt[nq],nxt[q],sizeof nxt[q]);
fa[nq] =fa[q];
num[nq] = num[q];
l[nq] = l[p]+;
fa[np] =fa[q] =nq;
while (nxt[p][c]==q){
nxt[p][c]=nq;
p = fa[p];
}
}
}
int temp = last;
while (temp){
if (num[temp]>=k){
break;
}
num[temp]++;
if (num[temp]==k){
ans+=l[temp]-l[fa[temp]];
}
temp = fa[temp];
}
}
}sam;
int main(){
while (scanf("%s",s)!=EOF){
scanf("%d%d",&m,&k);k++;
n=len = strlen(s);
sam.init();
for (int i=;i<len;i++){
sam.add(s[i]-'A');
}
ll ans1=sam.ans;
k=m;
sam.init();
for (int i=;i<len;i++){
sam.add(s[i]-'A');
}
ll ans2=sam.ans;
printf("%lld\n",ans2-ans1);
}
return ;
}

ACM-ICPC 2018 焦作赛区网络预赛 H、L的更多相关文章

  1. ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)

    Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...

  2. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

    There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...

  3. ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  4. ACM-ICPC 2018 焦作赛区网络预赛

    这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...

  5. ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports

    Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 L 题 Poor God Water

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  8. ACM-ICPC 2018 焦作赛区网络预赛 I题 Save the Room

    Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

    There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...

随机推荐

  1. 一份最贴近真实面试的Java基础面试题

    这是一份Java基础知识的面试题.在网上的关于Java的面试题数不胜数,但认真看过感觉大多数都没有实用性,有很多是面试官根本就不会问到的,那些已经脱离了实际开发的技术问题.而这份资料来源自一份个人觉得 ...

  2. Tomcat7的安装与配置

    Tomcat的安装及配置我曾经使用过tomcat,并实现了一个简单的servlet程序.没想到再次安装tomcat的时候用浪费了我大半天的时间.我想有必要做个总结,否则下次不知又要花费我多少时间. 1 ...

  3. 一次执行两个npm "start": "concurrently 'npm:dev' 'npm:json-server'"

    用的这个程序 concurrently 说是再有异步的时候,&& 就不好使,而且&& 也不能执行npm 只能执行命令 官方地址:https://www.npmjs.co ...

  4. Java会话(session)管理

    会话概述 什么是会话 简单的理解:用户打开浏览器,点击多个超链接,访问Web服务器上多个资源,然后关闭浏览器,整个过程称之为一次会话. 需要解决的问题 每个用户在使用浏览器与服务器会话的过程中,会产生 ...

  5. spring注解开发-扩展原理(源码)

    1.BeanFactoryPostProcessor BeanPostProcessor:bean后置处理器,bean创建对象初始化前后进行拦截工作的; BeanFactoryPostProcesso ...

  6. Hash冲突的几种解决方法

    1. 开放定值法: 也叫再散列法,当关键字key的哈希地址p=H(key)出现冲突时,以p为基础,产生另一个哈希地址p1,如果p1仍然冲突,再以p为基础,产生另一个哈希地址p2,…,直到找出一个不冲突 ...

  7. JDK的4种引用类型

    在java中,大致有以下几种引用类型,强引用(StrongReference).软引用(SoftReference).弱引用(WeakReference).虚引用(PhantomReference) ...

  8. c++_加法变乘法

    加法变乘法 我们都知道:1+2+3+ ... + 49 = 1225现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015 比如:1+2+3+...+10*11+12+...+27*28+29+ ...

  9. 【Codeforces 1083A】The Fair Nut and the Best Path

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们最后要的是一条最长的路径. 这条路径的权值和是所有点的权值和-所有边的权值和且这个值最大. 显然如果我们在某一条边上的累计的权值和< ...

  10. Fiddler抓包-工具介绍(request和response)

    from:https://www.cnblogs.com/yoyoketang/p/6731121.html 本篇简单的介绍下fiddler界面的几块区域,以及各自区域到底是干什么用的,以便于各好的掌 ...