• hdu3709


    枚举+数位dp

    注意处理数字为0和1的情况。

    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    #define D(x) 
    
    const int MAX_DIGIT = 20;
    
    long long n;
    int f[MAX_DIGIT];
    long long memoize[MAX_DIGIT][20*20*9];
    int pivot;
    
    int to_digits(long long a)
    {
        int ret = 0;
        while (a > 0)
        {
            f[++ret] = a % 10;
            a /= 10;
        }
        return ret;
    }
    
    long long dfs(int digit, bool less, int weight)
    {
        if (digit <= 0)
        {
            return weight == 0;
        }
        if (less && memoize[digit][weight] != -1)
        {
            return memoize[digit][weight];
        }
        int limit = less ? 9 : f[digit];
        long long ret = 0;
        for (int i = 0; i <= limit; i++)
        {
            int new_weight = weight + (digit - pivot) * i;
            if (new_weight < 0)
            {
                continue;
            }
            ret += dfs(digit - 1, less || i < f[digit], new_weight);
        }
        memoize[digit][weight] = ret;
        return ret;
    }
    
    long long work(long long n)
    {
        if (n < 0)
        {
            return 0;
        }
        int len = to_digits(n);
        long long ret = 0;
        for (int i = 1; i <= len; i++)
        {
            pivot = i;
            memset(memoize, -1, sizeof(memoize));
            ret += dfs(len, false, 0);
        }
        return ret - len + 1;
    }
    
    int main()
    {
        int t;
        scanf("%d", &t);
        while (t--)
        {
            long long a, b;
            scanf("%lld%lld", &a, &b);
            printf("%lld
    ", work(b) - work(a - 1));
        }
        return 0;
    }
    View Code
  • 相关阅读:
    山东省网络安全技能大赛 部分writeup
    网络安全实验室--SQL注入关
    PHP命令执行与防范
    练习平台,学习网站
    实验吧 简单的SQL注入1
    网络安全相关书籍
    Redtiger SQL注入练习(一)
    Redtiger SQL注入练习(二)
    南邮。。。综合题
    实验吧:让我进去
  • 原文地址:https://www.cnblogs.com/rainydays/p/4286398.html
Copyright © 2020-2023  润新知