一眼看出是数位dp,套模板就可以了。
但可能我太菜了吧,只能算11位的,10位就完全错了,233。
导致强行特判233。
求dalao们查错。
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL dp[12][10][10][3][4];
LL x,y;
int digit[12],len;
/*
0: 。。。。。
1:有两个相邻
2:有三个相邻
*/
/*
exist 0:.
1:8
2:4
3:4&&8
*/
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline LL read()
{
LL x=0;
char c=nc();
while(c<'0'||c>'9')c=nc();
while(c<='9'&&c>='0')x=x*10+c-'0',c=nc();
return x;
}
inline LL DFS(int pos,int limit,int pre,int pre_pre,int sta,int exist)
{
if(exist==3)return 0;
if(pos==0)return sta==2&&exist!=3;
if(!limit&&dp[pos][pre][pre_pre][sta][exist]!=-1)return dp[pos][pre][pre_pre][sta][exist];
int up=limit?digit[pos]:9;
LL tmp=0;
for(int i=0;i<=up;i++)
{
int new_exist=exist;
if(exist==1&&i==4)new_exist=3;
else if(exist==2&&i==8)new_exist=3;
else if(i==4)new_exist=2;
else if(i==8)new_exist=1;
int new_sta=sta;
if(sta!=2)
{
if(i==pre&&i==pre_pre)new_sta=2;
else if(i==pre)new_sta=1;
}
tmp+=DFS(pos-1,limit&&i==up,i,pre,new_sta,new_exist);
}
if(!limit)dp[pos][pre][pre_pre][sta][exist]=tmp;
return tmp;
}
inline LL cal(LL x)
{
len=0;
while(x)digit[++len]=x%10,x/=10;
return DFS(len,1,0,0,0,0);
}
int main()
{
//freopen("in.txt","r",stdin);
memset(dp,-1,sizeof(dp));
x=read(),y=read();
x==10000000000?cout<<cal(y)-5899826978:cout<<cal(y)-cal(x-1);
return 0;
}