Test Instructions: number of numbers that do not contain 4 and 62 in the statistical interval [A, b].
problem: This is the beginning of the digital DP, the first to understand the principle of number DP, Dp[i] [j]: Represents the first bit of the J value, for a chestnut: if 4715 digits is from right to left, then the first digit is 5, the second is 1, the third is 7, the fourth digit is 4. So if you require 0 to 4715,ans=dp[4][x]+dp[3][y]+dp[2][z]+dp[1][k]
0<=x<=4 (but 4 to be removed), 0<=y<=9,0<=z<=9,0<=k<=9 (also pay attention to the judgment, the 62, and 4 removed)
AC Code:
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstdio>#include<string>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Const intinf=0x3f3f3f3f; typedefLong Longll;typedef unsignedLong Longull;#definePrN printf ("\ n")#defineSI (n) scanf ("%d",& (n))#defineSII (n,m) scanf ("%d%d",& (N),& (M))#defineSIII (n,m,k) scanf ("%d%d%d",& (N),& (M),& (K))#defineCLE (A,val) memset (A, (Val), sizeof (a))#defineRep (i,b) for (int i=0;i< (b); i++)#defineREP (I,A,B) for (int i= (a); i<= (b); i++)#defineREReP (I,A,B) for (int i= (a); i>= (b); i--)Const intmax_n= ++5 ;Const Doubleeps= 1e-9 ;intdp[Ten][Ten];intSolintN) { int*dig=New int[Ten]; intlen=1; while(n) {Dig[len++]=n%Ten; N/=Ten; } intans=0; for(inti=len-1; i!=0; i--) { for(intj=0; j<dig[i]; J + +) { if(j!=4&&! (dig[i+1]==6&&j==2)) Ans+=Dp[i][j]; } if(dig[i]==4|| (dig[i]==2&&dig[i+1]==6)) Break; } returnans;}intMain () {#ifndef Online_judge//freopen ("C:\\users\\zmy\\desktop\\in.txt", "R", stdin);//freopen ("C:\\users\\zmy\\desktop\\out.txt", "w", stdout);#endif //Online_judgedp[0][0]=1; for(intI=1; i<=7; i++) { for(intj=0; j<=9; J + +) { for(intk=0; k<=9; k++) { if(j!=4&& (j!=6|| k!=2) ) {Dp[i][j]+=dp[i-1][k]; } } } } intL,r; while(cin>>l>>r,l| |r) {cout<<sol (r+1)-sol (L) <<Endl; } return 0;}
HDU 2089 do not 62 (digital DP Primer)