/*do a few digits DP violent words don't know how many sets of data will t so write DP thinking on and math textbook that "no more than xxx X-bit even have a few" here can be similar to maintain a prefix and appearance of something (but also different from the prefix and) state: F[i][j] The number of I-digits that start with J is the number of conditions (J can be 0) and then it can be processed, like a 10000 of this integer number, and then for an incomplete number like 123456, the first place to find a position is 1, and the number of all qualifying numbers starting with 6 is 2. In the beginning of the 5 .... etc.*/#include<iostream>#include<cstdio>#include<cstring>using namespacestd;intst,en,ans,data[Ten],l,f[Ten][Ten];voidReady () {f[0][0]=1; for(intI=1; i<=7; i++)//number of enumeration bits for(intj=0; j<=9; j + +)//enum What is the first I for(intk=0; k<=9; k++)//enumeration of what I-1 is if((j==6&&k==2)|| j==4|| k==4)Continue;//Shed Elsef[i][j]+=f[i-1][k];}voidGet_data (intx) { while(x>0) {data[++l]=x%Ten; X=x/Ten; }}intSlove (intx) {ans=0; l=0; memset (data,0,sizeof(data)); Get_data (x);//get each number to be torn down what for(inti=l;i>=1; i--)//the number of bits enumerated from the low { for(intj=0; j<data[i];j++)//enumeration of the I-bit is what enumerates to <data[i] if((j==2&&data[i+1]==6)|| j==4)Continue; Elseans+=F[i][j]; if(data[i]==4|| (data[i]==2&&data[i+1]==6)) Break;//I'm going to have to look for this 4 or 62. } returnans;}intMain () {//freopen ("cin.in", "R", stdin); //freopen ("Test.out", "w", stdout);Ready (); while(1) {scanf ("%d%d",&st,&en); if(st==0&&en==0) Break; printf ("%d\n", Slove (en+1)-Slove (ST)); } return 0;}
HUD 2,089-digit DP