题目

把\(s\)串所有长度为\(\lfloor \frac{d}{2}\rfloor\)的子串插入一个ACAM中,之后数位dp就好了,状态是\(dp_{i,j,0/1}\)第\(i\)位,在ACAM上的节点\(j\),不卡/卡上界;正难则反一下,统计所有不能被表示即没有经过结束标记的路径即可

注意前导0的处理

代码

#include<bits/stdc++.h>
#define re register
#define LL long long
const int mod=1e9+7;
char S[1005],A[55],B[55];int d;
int fa[1005*50],son[1005*50][10],f[1005*50],cnt;
int dp[2][1005*25][2],n,lm[55];
inline int dqm(int x) {return x<0?x+mod:x;}
inline int qm(int x) {return x>=mod?x-mod:x;}
inline void ins(int l,int r) {
int nw=0;
for(re int i=l;i<=r;++i) {
if(!son[nw][S[i]-'0']) son[nw][S[i]-'0']=++cnt;
nw=son[nw][S[i]-'0'];
}
f[nw]=1;
}
inline int solve(char *H) {
int ans=0;
for(re int i=1;i<=d;i++) lm[i]=H[d-i+1]-'0';
for(re int i=d;i;i--) ans=10ll*ans%mod,ans=qm(ans+lm[i]);
int o=0;memset(dp,0,sizeof(dp));dp[0][0][1]=1;
for(re int i=d;i;--i,o^=1) {
memset(dp[o^1],0,sizeof(dp[o^1]));
for(re int j=0;j<=cnt;++j) {
if(!dp[o][j][0]) continue;
for(re int k=0;k<=9;++k) {
if(f[son[j][k]]) continue;
dp[o^1][son[j][k]][0]=qm(dp[o^1][son[j][k]][0]+dp[o][j][0]);
}
}
for(re int j=0;j<=cnt;++j) {
if(!dp[o][j][1]) continue;
for(re int k=0;k<lm[i];++k) {
if(f[son[j][k]]) continue;
dp[o^1][son[j][k]][0]=qm(dp[o^1][son[j][k]][0]+dp[o][j][1]);
}
if(!f[son[j][lm[i]]])
dp[o^1][son[j][lm[i]]][1]=qm(dp[o^1][son[j][lm[i]]][1]+dp[o][j][1]);
}
if(i==d&&!f[son[0][0]]) dp[o^1][son[0][0]][0]=dqm(dp[o^1][son[0][0]][0]-1);
if(i!=d) {
for(re int j=1;j<=9;j++) {
if(f[son[0][j]]) continue;
dp[o^1][son[0][j]][0]=qm(dp[o^1][son[0][j]][0]+1);
}
}
}
for(re int i=0;i<=cnt;i++) ans=dqm(ans-dp[o][i][0]),ans=dqm(ans-dp[o][i][1]);
return ans;
}
inline int chk(char *H) {
int nw=0;
for(re int i=1;i<=d;i++) {nw=son[nw][H[i]-'0'];if(f[nw]) return 1;}
return 0;
}
int main() {
scanf("%s",S+1);n=strlen(S+1);scanf("%s",A+1);scanf("%s",B+1);d=strlen(A+1);
for(re int i=1;i+(d>>1)-1<=n;i++) ins(i,i+(d>>1)-1);
std::queue<int> q;
for(re int i=0;i<=9;i++) if(son[0][i]) q.push(son[0][i]);
while(!q.empty()) {
int k=q.front();q.pop();f[k]|=f[fa[k]];
for(re int i=0;i<=9;i++)
if(son[k][i])fa[son[k][i]]=son[fa[k]][i],q.push(son[k][i]);else son[k][i]=son[fa[k]][i];
}
printf("%d\n",(solve(B)-solve(A)+mod+chk(A))%mod);
return 0;
}

CF585F Digits of Number Pi的更多相关文章

  1. 题解 CF585F 【Digits of Number Pi】

    考虑用数位 \(DP\) 来统计数字串个数,用 \(SAM\) 来实现子串的匹配. 设状态 \(f(pos,cur,lenth,lim,flag)\),表示数位的位数,在 \(SAM\) 上的节点,匹 ...

  2. [CodeForces-585F]Digits of Number Pi

    题目大意: 给你一个数字串s,一个序列范围l和r,(l和r的数字位数为d)求l到r中有多少个数,满足它的长度为d/2的子串,能够在s中被匹配. 思路: 首先将s中每一个长度为d/2的子串插入后缀自动机 ...

  3. 【leetcode】1295. Find Numbers with Even Number of Digits

    题目如下: Given an array nums of integers, return how many of them contain an even number of digits. Exa ...

  4. 数学符号π (Pi)、Σ(Capital Sigma)、μ (Mu) 、σ(sigma)、∏(capital pi), ∫(Integral Symbol)的来历

    1.π (Pi; periphery/周长) March 14 marks Pi Day, the holiday commemorating the mathematical constant π ...

  5. [LeetCode] Happy Number 快乐数

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  6. [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  7. [Swift]LeetCode258. 各位相加 | Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  8. UVALive 4877 Non-Decreasing Digits 数位DP

    4877 Non-Decreasing Digits A number is said to be made up ofnon-decreasing digitsif all the digits t ...

  9. POJ 1350 Cabric Number Problem (模拟)

    题目链接 Description If we input a number formed by 4 digits and these digits are not all of one same va ...

随机推荐

  1. git 上传本地代码

    新增本地代码到远程库 http://blog.csdn.net/hanhailong726188/article/details/46738929 github配置教程 http://www.runo ...

  2. P1001 A+B Problem

    下面我们要展示这个题的玄学做法!!!@cjx!!! #include<iostream> #define chen using namespace std; #define jia int ...

  3. c# WInform 自定义导航布局

    问题形成原因:软件一般都是左侧树导航或上部菜单导航,做好一个软件后,有的客户可能想用一个页面做导航图像,而各个客户用的功能可能不同,所以导航布局需要自定义. 思路:1.把菜单列出来 2.双击菜单生成一 ...

  4. [unity基础教程]Unity3D实现动态载入游戏资源(转)

    用Unity3D制作基于web的网络游戏,不可避免的会用到一个技术-资源动态载入.比方想载入一个大场景的资源,不应该在游戏的開始让用户长时间等待全部资源的载入完成.应该优先载入用户附近的场景资源.在游 ...

  5. js自增++与自减--运算符

    /** * 自增(++)与自减(--)运算符 */ // 自增示例 var a = 1, c, d, e; console.log(`a++ = ${a++}`); // a++ = 1 consol ...

  6. 2018-8-10-win10-uwp-httpClient-登陆CSDN

    title author date CreateTime categories win10 uwp httpClient 登陆CSDN lindexi 2018-08-10 19:16:53 +080 ...

  7. 一、Nuget管理

    一.注册账号 http://www.nuget.org 可用微软账户登录注册 手机端授权 二.打包Nuget 1.新建一个.NET Standard 的类库项目(取名类库) 更改方法 2.选择项目属性 ...

  8. 一、bootstrap-fontawesome-iconpicker组件

    一.bootstrap-fontawesome-iconpicker组件 <!DOCTYPE html> <html lang="en"> <head ...

  9. Linux Centos 7 下部署 .NetCore + MySql + Redis + mssql2007 部署过程

    1.  net core 安装及运行配置 安装 1)rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-p ...

  10. lsyncd+rsync文件实时同步

    1.rsync两端都需要安装 yum -y install rsync 2.提供lsyncd的安装源 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x ...