The data range is so small. Feel the violence can be past AH.
DP is also a casual design state
F [I][J][k][s][L] Represents the former i Bit, the last one is J The last one appeared continuously k Times (if K is already equal to 3 then it remains the same) s Said 4,8 The presence state of l Indicates whether the prefix is the same as the prefix of the original number
The shift is to enumerate the next transfer, and it's simple.
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<ctime>
#include<set>
#include<map>
#define N 110000
#define ll long long
using namespace std;
int S[11]={0,0,0,0,1,0,0,0,2,0,0};
long long f[13][10][4][4][2],L,R;
int a[22];
long long cal(long long x)
{
if(x<10000000000LL)return 0;
memset(f,0,sizeof(f));
for(int i=11;i>=1;i--) a[i]=x%10,x/=10;
for(int i=1;i<=a[1];i++) ++f[1][i][1][S[i]][i==a[1]];
for(int i=1;i<=10;i++)
for(int j=0;j<=9;j++)
for(int k=1;k<=3;k++)
for(int s=0;s<3;s++)
{
if(f[i][j][k][s][0])
{
for(int l=0;l<=9;l++)
f[i+1][l][k==3?3:(l==j?k+1:1)][s|S[l]][0]+=f[i][j][k][s][0];
}
if(f[i][j][k][s][1])
{
for(int l=0;l<=a[i+1];l++)
f[i+1][l][k==3?3:(l==j?k+1:1)][s|S[l]][l==a[i+1]]+=f[i][j][k][s][1];
}
}
long long ans=0;
for(int j=0;j<=9;j++)
for(int l=0;l<=1;l++)
ans+=f[11][j][3][0][l]+f[11][j][3][1][l]+f[11][j][3][2][l];
return ans;
}
int main()
{
scanf("%lld%lld",&L,&R);
printf("%lld\n",cal(R)-cal(L-1));
return 0;
}
4521: [Cqoi2016] Mobile phone number | Digital DP