C - 不要62

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <string>
 6 #include <cmath>
 7 
 8 #define Faster ios::sync_with_stdio(false),cin.tie(0)
 9 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
10 #define Close fclose(stdin),fclose(stdout)
11 const int maxn = 1e5 + 5;
12 using namespace std;
13 const int MOD = 1e9+7;
14 typedef long long ll;
15 int a[maxn];
16 int dp[maxn][2];
17 
18 int dfs(int pos, int pre, int sta, bool limit){
19     if(pos == -1) return 1;
20     if(!limit && dp[pos][sta] != -1) return dp[pos][sta];
21     int up = limit? a[pos]:9;
22     int tmp = 0;
23     for(int i = 0;i <= up;i++){
24         if(pre == 6 && i == 2)
25             continue;
26         if(i == 4)
27             continue;
28         tmp += dfs(pos-1, i, i == 6, limit && i == a[pos]);
29     }
30     if(!limit) dp[pos][sta] = tmp;
31     return tmp;
32 }
33 
34 //从 1到x 的满足的数量
35 int solve(int x){
36     int pos = 0;
37     while(x){
38         a[pos++] = x%10;
39         x /= 10;
40     }
41     return dfs(pos-1, -1, 0, true);
42 }
43 
44 int main(){
45     Faster;
46     int l, r;
47     while(cin >> l >> r){
48         if(l == 0 && r == 0)
49             break;
50         memset(dp, -1, sizeof dp);
51         int ans = solve(r) - solve(l-1);
52         cout << ans << endl;
53     }
54      return 0; 
55  }

 dalao博客:https://blog.csdn.net/wust_zzwh/article/details/52100392

posted @ 2018-05-26 14:08  ouyang_wsgwz  阅读(265)  评论(0编辑  收藏  举报