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. Python学习日记之Python函数及方法使用总结

    1.  DocStrings 文档字符串     可以直接输出位于函数内定义的说明 # -*- coding:utf-8 -*- def printMax(x, y): '''示例: 说明文档''' ...

  2. [python3]PyCharm编辑器

    简介 Python有丰富的开发工具,本教程不一一进行介绍,只推荐大家使用PyCharm,因为python开发者都在用它,但缺点就是消耗电脑资源,如果你电脑配置低,就会比较卡 下载 下载地址: http ...

  3. HDU 5391 Zball in Tina Town (打表,水)

    题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...

  4. (转)在编写Spring框架的配置文件时,标签无提示符的解决办法

    http://blog.csdn.net/yerenyuan_pku/article/details/52831618 问题描述 初学者在学习Spring框架的过程中,大概会碰到这样一个问题:在编写S ...

  5. 1-1 编程基础 GCC程序编译

    GCC简介      Linux系统下的gcc是GNU推出的强大.性能优越的多平台编译器,是GNU的代表作之一.gcc可以在多种硬体平台上编译出可执行程序,其执行效率与一般的编译器相比平局效率要高20 ...

  6. iview table 勾选当前行代码 data key _checked: true

    给 data 项设置特殊 key _checked: true 可以默认选中当前项

  7. 解决WampServer窗口界面乱码问题

    软件版本:WampServer 3.1.4 问题描述:Wamp安装完成.点击图标,发现导航界面乱码,也可能使用中没遇到这种问题.如下: 用记事本打开 wampmanager.ini 和 wampman ...

  8. js 数组元素排序?

    Part.1  sort 方法 js 有自带排序方法 sort(),  默认 升序 排列 如: data() { return { arr: [1,3,2,5,6,8,7,4,9] } }, 控制台如 ...

  9. 搜索 || DFS || POJ 1321 棋盘问题

    棋盘上#可以放,.不可以放,每行每列只能放一个 *解法:类似八皇后问题 dfs+回溯,考虑每一行和每一列 [[[[dfs的样子]]]]最前面写达到目标状态or不能走下去了 然后return #incl ...

  10. flash player vista or win7

    win10 or 8 firefox https://fpdownload.adobe.com/get/flashplayer/pdc/31.0.0.122/install_flash_player. ...