标签:name namespace state mit continue pos tin lead int
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int n,m,f[55][55],num[55],len; 6 int dp(int pos,int state,int lead,int limit) 7 { 8 if(pos==0)return 1; 9 if(!lead&&!limit&&(~f[pos][state]))return f[pos][state]; 10 int up=limit?num[pos]:9,ans=0; 11 for(int i=0;i<=up;i++) 12 { 13 if(i==4||(state==6&&i==2))continue; 14 ans+=dp(pos-1,i,lead&&i==0,limit&&i==num[pos]); 15 } 16 if(!lead&&!limit)f[pos][state]=ans; 17 return ans; 18 } 19 int solve(int x) 20 { 21 memset(f,-1,sizeof(f));len=0; 22 while(x){num[++len]=x%10;x/=10;} 23 return dp(len,0,1,1); 24 } 25 int main() 26 { 27 while(cin>>n>>m) 28 { 29 if(!n&&!m)break; 30 printf("%d\n",solve(m)-solve(n-1)); 31 } 32 return 0; 33 }
标签:name namespace state mit continue pos tin lead int
原文地址:https://www.cnblogs.com/szmssf/p/11349773.html