Feeling get to a new position in the digital DP, plus one that says there is no limit to the number currently being filled (it feels silly to write in the past).
There are two places to be aware of:
1. Each DP to one needs to f[i][the initial state of]++, the equivalent of the former is the leading 0 (this problem I filled the first two bits two 10 as the initial state).
2. Because there are 1, so the first position after the initial state can not fill 0, requires a special
F[i][j][k][l][p][q][o] Indicates to fill in the first, upper and upper, what is the difference, whether the 4,8 has occurred, whether three consecutive occurrences, and whether the current bit is limited.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define LL Long Longusing namespace std;ll pw[100];ll f[20][11][11][2][2][2][2];//Digit Upper This 4 8 appears 0/1 limit 0/1 ll solve (ll x) {pw[0]=1;for (int i=1;i<=12;i++) pw[i]=pw[i-1]*10;int pos;for (int i=0;i<=12;i++) if (X>=pw[i]) Pos=i+1;memset (f,0,sizeof (f)); f[0][10][10][0][0][0][1]=1;for (int i=1;i<=pos;i++) {int ks=x/pw[pos-i]%10; f[i][10][10][0][0][0][0]=1;//Brush table for (int. j=0;j<=10;j++) {for (int. k=0;k<=10;k++) {for (int. l=0;l<=1;l++) {for ( int p=0;p<=1;p++) {//this for (int q=0;q<=9;q++) {if (j==10&&k==10&q==0) Continue;bool b1=0,c1=0,d1=0; if (j==k&&j==q) b1=1;if (q==4) c1=1;if (q==8) d1=1;f[i][k][q][l|c1][p|d1][1][0]+=f[i-1][j][k][l][p][1][0];f[ I][K][Q][L|C1][P|D1][B1][0]+=F[I-1][J][K][L][P][0][0];} for (int q=0;q<=ks;q++) {if (j==10&&k==10&q==0) Continue;bool b1=0,c1=0,d1=0;if (J==K&&J==Q) B1 =1;if (q==4) c1=1;if (q==8) d1=1;if (q!=ks) {f[i][k][q][l|c1][p|d1][1][0]+=f[i-1][J][K][L][P][1][1];F[I][K][Q][L|C1][P|D1][B1][0]+=F[I-1][J][K][L][P][0][1];} else {f[i][k][q][l|c1][p|d1][1][1]+=f[i-1][j][k][l][p][1][1];f[i][k][q][l|c1][p|d1][b1][1]+=f[i-1][j][k][l][p][ 0][1];}}}}}} ll ans=0;for (int i=0;i<=9;i++) for (int j=0;j<=9;j++) for (int. k=0;k<=1;k++) for (int. l=0;l<=1;l++) for (int s=0 ; s<=1;s++) {if (k&&l) continue;ans+=f[pos][i][j][k][l][1][s];} return ans;} ll L,r;int Main () {scanf ("%lld%lld", &l,&r);p rintf ("%lld\n", Solve (R)-solve (L-1)); return 0;}
Bzoj 4521: [Cqoi2016] Mobile phone number