http://codeforces.com/contest/1129/problem/C

#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pqueue priority_queue
#define NEW(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x&(-x))
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define lc (d<<1)
#define rc (d<<1|1)
const double pi=4.0*atan(1.0);
const double e=exp(1.0);
const int maxn=1e6+;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+;
const ULL base=1e7+;
using namespace std;
LL a[maxn],b[maxn],Next[maxn];
LL dp[][];
void get_next(int m){
Next[]=-;
int k=-;
int j=;
while(j<m){
while(k>-&&b[k]!=b[j]){
k=Next[k];
}
if(b[k]==b[j]||k==-){
k++;
}
Next[++j]=k;
}
}
bool kmp(int n,int m){
int k=;
for(int i=n-m+;i<=n;i++){
b[k++]=a[i];
}
get_next(m);
k=;
for(int i=;i<n;i++)
{
while(k>&&b[k]!=a[i]){
k=Next[k];
}
if(b[k]==a[i]){
k++;
}
if(k==m){
return ;
}
}
return ;
}
bool check(int l){
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
if(a[l]==&&a[l+]==&&a[l+]==&&a[l+]==) return ;
return ;
}
int main(){
int n;
LL sum=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(i==){
dp[][]=;
printf("1\n");
}
else{
int l=,r=i;
int ans=;
while(l<=r){
int mid=(l+r)>>;
if(kmp(i,mid)){
l=mid+;
ans=max(ans,mid);
}
else{
r=mid-;
}
}
dp[i][i]=;
if(i>) dp[i-][i]=;
if(i>) dp[i-][i]=;
if(i>&&check(i-)) dp[i-][i]=;
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i-][i];
dp[j][i]%=mod;
}
for(int j=i-;j>=;j--){
dp[j][i]+=dp[j][i-]*dp[i][i];
dp[j][i]%=mod;
}
for(int j=i-ans;j>=;j--){
sum+=dp[j][i];
sum%=mod;
}
printf("%lld\n",sum);
}
}
}

Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)的更多相关文章

  1. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  2. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2

    A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...

  3. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)

    A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...

  4. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)C. Morse Code

    题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹 ...

  5. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)

    A - Toy Train 很显然,一个站有多少个糖,那么就要从这个点运多少次.设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段.很显然最后一段越小越好. 然后枚举起点后, ...

  6. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解

    A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...

  7. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  8. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  9. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

随机推荐

  1. 前端表单提交数据~php获取表单内容

    上图代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  2. 搭建 Jest+ Enzyme 测试环境

    1.为什么要使用单元测试工具? 因为代码之间的相互调用关系,又希望测试过程单元相互独立,又能正常运行,这就需要我们对被测函数的依赖函数和环境进行mock,在测试数据输入.测试执行和测试结果检查方面存在 ...

  3. Centos 7环境下安装配置Hadoop 3.0 Beta1简记

    前言 由于以前已经写过一篇Centos 7环境下安装配置2.8的随笔,因此这篇写得精简些,只挑选一些重要环节记录一下. 安装环境为:两台主机均为Centos 7.*操作系统,两台机器配置分别为: 主机 ...

  4. Wow64(32位进程)注入DLL到64位进程

    转载自: https://blog.poxiao.me/p/wow64-process-inject-dll-into-x64-process/ 向其他进程注入DLL通常的做法是通过调用CreateR ...

  5. 使用阿里云Java SDK 实现 DDNS

    本代码的实现前提: 1.拥有阿里云域名,且获取了Access Key 及 Access Secret 2.能获取外网IP的页面地址(注意:ip138.com的实际包含ip地址为http://2018. ...

  6. java 的Date 日期相关操作

    String 与 Date互转(1)基于SimpleDateFormat实现: package com.bky.df; import java.text.ParseException; import ...

  7. Source Insight 4.0安装后首次打开报错Unable to open or create

    错误提示大概如下: Unable to open or create ....我的文档/source insght4.0/xxx.sidb. 这个错误提示就是找不到这个文件,原因是应为有中文路径,那么 ...

  8. 数据库中id为自增

    使用find_and_modify函数可以设置mongo的id为自增 且可以支持原有的高并发操作,find_and_modify函数完成更新查找两个操作其是原子性的操作 代码:(auto_id.py) ...

  9. eclipse 安装MyBatis插件 -- 官网直接拖动“安装”

    拖动“安装” http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2947754

  10. C# 反射,动态类,动态方法

    1.动态类名,固定方法名,例如.调用不同类下边的GetById()方法: //项目需要引用Miscorsoft.CSharp类库,否则会报错:找不到编译动态表达式所需的一个或者多个类型.//引用这两个 ...