标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=8; int a[maxn]; int dp[maxn][2]; int dfs(int len,bool state,bool e) { if(!len) return 1; if(e&&dp[len][state]!=-1) return dp[len][state]; int last=e?9:a[len]; int ret=0; for(int i=0;i<=last;i++){ if(i==4 || state && i==2) continue; ret+=dfs(len-1,i==6,e||i<a[len]); } return dp[len][state]=ret; } int solve(int n) { memset(dp,-1,sizeof dp); int len=0; while(n){ a[++len]=n%10; n/=10; } return dfs(len,false,false); } int main() { int n,m; while(scanf("%d %d",&n,&m)){ if(!n&&!m) break; printf("%d\n",solve(m)-solve(n-1)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4836967.html