首页 技术 正文
技术 2022年11月21日
0 收藏 810 点赞 3,936 浏览 1048 个字

题目

洛谷

数位动规用爆搜真好玩

做法

含有回文串实际我们仅需判断是否有\(2/3\)回文串

\(Dfs(now,num,pre,ly,lead,prel,top)\):

在第\(now\)位

\(now-1\)位,\(now-2\)位

是否合法

\(now-1\)位是否为前导\(0\),\(now-2\)为是否为前导\(0\)

是否受限

My complete code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn=1009,p=1e9+7;
LL ans;
LL a[maxn],f[maxn][10][10][2][2][2];
char s1[maxn],s2[maxn];
LL Dfs(LL now,LL num,LL pre,LL ly,LL lead,LL prel,LL top){
if(!now) return ly;
if(!top && f[now][num][pre][ly][lead][prel]!=-1) return f[now][num][pre][ly][lead][prel];
LL ret(0);
LL Up=top?a[now]:9;
for(LL i=0;i<=Up;++i)
(ret+=Dfs(now-1,i,num,ly||(!lead&&i==num)||(!prel&&i==pre),lead&&!i,lead,top&&(i==Up))%p)%=p;
if(!top) f[now][num][pre][ly][lead][prel]=ret;
return ret;
}
int main(){
scanf(" %s %s",s1+1,s2+1);
LL nl(strlen(s1+1)),nr(strlen(s2+1));
LL tot(0);
for(LL i=nr;i>=1;--i) a[++tot]=s2[i]-'0';
memset(f,-1,sizeof(f));
ans+=Dfs(tot,0,0,0,1,1,1);
tot=0;
for(LL i=nl;i>=1;--i) a[++tot]=s1[i]-'0';
if(nl==1 && a[1]==0){
cout<<ans;
return 0;
}
--a[1];
LL now(1);
while(a[now]<0){
a[now]=9;
--a[++now];
}
while(a[tot]==0) --tot;
ans=(ans-Dfs(tot,0,0,0,1,1,1)+p)%p;
cout<<ans;
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,918
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,444
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,255
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,069
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,702
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,741