标签:des style blog color os io java strong for
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19640 Accepted Submission(s):
6697
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 7 int dp[7][10]; 8 int hxl[10],hlen; 9 void init() 10 { 11 dp[0][0]=1; 12 for(int i=1;i<=6;i++)//枚举有几位 13 { 14 for(int j=0;j<=9;j++)//第 i 为的数字 15 { 16 for(int s=0;s<=9;s++)/** i -1 **/ 17 if(j!=4 && !(j==6&&s==2)) 18 dp[i][j] = dp[i][j] +dp[i-1][s]; 19 } 20 } 21 } 22 int solve(int k) 23 { 24 hlen = 0; 25 while(k) 26 { 27 hxl[++hlen] = k%10; 28 k = k/10; 29 } 30 int sum = 1; 31 for(int i=hlen;i>=1;i--) 32 { 33 for(int j=0;j<hxl[i];j++) 34 if(j!=4 && !(i+1<=hlen&&j==2&&hxl[i+1]==6)) 35 sum = sum+dp[i][j]; 36 if(hxl[i]==4 || (i+1<=hlen&&hxl[i]==2 && hxl[i+1]==6)){ 37 sum --; 38 break; 39 } 40 } 41 return sum; 42 } 43 int main() 44 { 45 int n,m; 46 init(); 47 48 while(scanf("%d%d",&n,&m)>0) 49 { 50 if(n==0&&m==0)break; 51 printf("%d\n",solve(m)-solve(n-1)); 52 } 53 return 0; 54 }
标签:des style blog color os io java strong for
原文地址:http://www.cnblogs.com/tom987690183/p/3953579.html