标签:int spl none dfs scanf close sizeof pre \n
int a,b,shu[20],dp[20][11]; int dfs(int len,int pre, bool limit) { if(len==0) return 1; if(!limit&&dp[len][pre]!=-1) return dp[len][pre]; //有限制的情况会不一样 int cnt=0,maxx=(limit?shu[len]:9); //是否有限制 for(int i=0;i<=maxx;i++) { if(pre==4&&i==9) continue; cnt+=dfs(len-1,i,i==maxx&&limit); } return limit?cnt:dp[len][pre]=cnt; } int solve(int x) { memset(shu,0,sizeof(shu)); int k=0; while(x) { shu[++k]=x%10; x/=10; } return dfs(k,-1,true); } int main() { while(scanf("%d%d",&a,&b),b!=0||a!=0) { printf("%d\n",solve(b)-solve(a-1)); } }
标签:int spl none dfs scanf close sizeof pre \n
原文地址:https://www.cnblogs.com/ww123/p/9569085.html