标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26743 Accepted Submission(s): 9385
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 6 using namespace std; 7 8 int f[11][11]; 9 10 void DP() 11 { 12 for(int i=0;i<=9;i++) 13 if(i!=4)f[1][i]=1; 14 for(int i=2;i<=9;i++) 15 for(int j=0;j<=9;j++) 16 if(j!=4) 17 for(int kk=0;kk<=9;kk++) 18 if(kk!=4&&!(j==6&&kk==2)) 19 f[i][j]+=f[i-1][kk]; 20 } 21 22 int get(int x) 23 { 24 int num[11],len=0,res=0; 25 while(x) 26 { 27 num[++len]=x%10; 28 x/=10; 29 } 30 for(int i=1;i<num[len];i++) 31 res+=f[len][i]; 32 for(int i=1;i<=len-1;i++) 33 for(int j=1;j<=9;j++) 34 res+=f[i][j]; 35 if(num[len]==4)return res; 36 for(int i=len-1;i>=1;i--) 37 { 38 for(int j=0;j<num[i];j++) 39 { 40 if(j==4 || (j==2 && num[i+1]==6) )continue; 41 res+=f[i][j]; 42 } 43 if(num[i]==4 || (num[i+1]==6 && num[i]==2) )break; 44 } 45 return res; 46 } 47 48 int main() 49 { 50 DP(); 51 int l,r,num,snum,ans=0; 52 while(1) 53 { 54 scanf("%d%d",&l,&r); 55 if(!(l&&r))break; 56 printf("%d\n",get(r+1)-get(l)); 57 } 58 return 0; 59 }
标签:
原文地址:http://www.cnblogs.com/tuigou/p/4832678.html