A template problem that belongs to a digital DP
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespaceStd;typedefLong LongLL;#defineMOD 2520intdp[ -][2];//dp[The length of the number [the first digit of the number];intbit[ -], p =0;intDfsintPosintFirstintflag) {
if(pos = =-1) { return 1; } if(!flag && Dp[pos][first]! =-1) returnDp[pos][first]; intAns =0, end; End= Flag?bit[pos]:9; for(intI=0; i<=end; i++) { if(i = =4)Continue; if(i = =2&& first)Continue; Ans+ = DFS (pos-1, i = =6, flag && End = =i); } if( !flag) Dp[pos][first]=ans; returnans;}intSolveintN) { intLen =0; while(n) {Bit[len+ +] = n%Ten; N/=Ten; } returnDFS (len-1,0,1);}intMain () {intA, B; Memset (DP,-1,sizeof(DP)); while(SCANF ("%d%d", &a,&b), A +b) {printf ("%d\n", solve (b)-Solve (A-1) ); } return 0;}
HDU do not 62 2089 digits DP