推荐以下一篇博客:https://blog.csdn.net/wust_zzwh/article/details/52100392
1.(HDOJ2089)http://acm.hdu.edu.cn/showproblem.php?pid=2089
分析:裸模板题
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 typedef long long ll; 6 int a[20]; 7 int dp[20][2]; 8 int dfs(int pos,int pre,int sta,bool limit) 9 { 10 if ( pos==-1 ) return 1; 11 if ( !limit && dp[pos][sta]!=-1 ) return dp[pos][sta]; 12 int up=limit?a[pos]:9; 13 int tmp=0; 14 for ( int i=0;i<=up;i++ ) 15 { 16 if ( pre==6 && i==2 ) continue; 17 if ( i==4 ) continue; 18 tmp+=dfs(pos-1,i,i==6,limit&&i==a[pos]); 19 } 20 if ( !limit ) dp[pos][sta]=tmp; 21 return tmp; 22 } 23 24 int solve(int x) 25 { 26 int pos=0; 27 while ( x ) 28 { 29 a[pos++]=x%10; 30 x/=10; 31 } 32 return dfs(pos-1,-1,0,true); 33 } 34 35 int main() 36 { 37 int l,r; 38 while ( scanf("%d%d",&l,&r)!=EOF && (l+r) ) 39 { 40 memset(dp,-1,sizeof(dp)); 41 printf("%d\n",solve(r)-solve(l-1)); 42 } 43 return 0; 44 }