• 不要62(一维记忆化搜索)


    你甚至可以只开一维(划掉)

    #include<bits/stdc++.h>
    #include<unordered_map>
    using namespace std;
    #define ll long long
    #define Ls t[p << 1]
    #define Rs t[p << 1 | 1]
    #define fastio ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    const int maxn = 3e5 + 10;
    const ll inf = 1e7;
    ll mod = 1e9 + 7;
    
    ll dp[15];
    
    int a[10];
    
    int dfs(int len, int last, int ismax)
    {
        int ans = 0, maxx;
        if (!len)return 1;
        if (!ismax && !last && dp[len] != -1)
            return dp[len];
        maxx = (ismax ? a[len] : 9);
        for (int i = 0; i <= maxx; i++)
        {
            if (i == 4)continue;
            if (last && i == 2)continue;
            ans += dfs(len - 1, i == 6, ismax && i == maxx);
            //cout << len << " " << i << " " << ans << endl;
        }
        if (!ismax && !last)dp[len] = ans;
        return ans;
    }
    
    int main()
    {
        //freopen("C:\1.in", "r", stdin);
        fastio;
        int n, m;
        while (cin >> n >> m, n, m)
        {
            memset(dp, -1, sizeof(dp));
            int cnt = 0;
            //m++;
            n--;
            while (n)
                a[++cnt] = n % 10, n /= 10;
            int ans = -dfs(cnt, 0, 1);
            //cout << ans << " ";
            memset(dp, -1, sizeof(dp));
            //cout << endl;
            cnt = 0;
            while (m)
                a[++cnt] = m % 10, m /= 10;
            ans += dfs(cnt, 0, 1);
            cout << ans << endl;
        }
        return 0;
    
    }
    
  • 相关阅读:
    [原]减小VC6编译生成的exe文件的大小
    [原]可用代码
    [原]BlogTemplate
    [原]Excel VBA数据校验
    Favorite
    [原]隐藏cnblogs侧边栏
    [原]Skills
    UI现在就升级到Windows7
    redis 笔记
    1 Two Sum(LeetCode HOT 100)
  • 原文地址:https://www.cnblogs.com/ruanbaiQAQ/p/13543067.html
Copyright © 2020-2023  润新知