• HDU


    链接:

    https://vjudge.net/problem/HDU-3652

    题意:

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.

    思路:

    数位DP,记录前面的余数,和前一位的数,和是否已经存在13.四维DP。
    如果不记录前一位的值,可能出现无法判断13是否存在。

    代码:

    // #include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    const int MOD = 1e9+7;
    const int MAXN = 1e6+10;
    
    LL F[20][20][2][10];
    LL dig[20];
    LL a, b, n;
    
    LL Dfs(int pos, int pre, int num, int ok, bool lim)
    {
        if (pos == -1)
        {
            if (pre == 0 && ok)
                return 1;
            return 0;
        }
        if (!lim && F[pos][pre][ok][num] != -1)
            return F[pos][pre][ok][num];
        int up = lim ? dig[pos] : 9;
        LL ans = 0;
        for (int i = 0;i <= up;i++)
            ans += Dfs(pos-1, ((pre*10)%13+i)%13, i, ok ? ok : (num == 1 && i == 3), lim && i == up);
        if (!lim)
            F[pos][pre][ok][num] = ans;
        return ans;
    }
    
    LL Solve(LL x)
    {
        int p = 0;
        while(x)
        {
            dig[p++] = x%10;
            x /= 10;
        }
        return Dfs(p-1, 0, -1, 0, 1);
    }
    
    int main()
    {
        // freopen("test.in", "r", stdin);
        memset(F, -1, sizeof(F));
        while(~scanf("%lld", &n))
        {
            printf("%lld
    ", Solve(n));
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    Ubuntu下的Apache、Mysql、PHP环境搭建
    JS代码引用位置问题-转
    mysql设置定时任务
    js setTimeout函数
    JavaScript向window onload添加加载函数
    写在开博之时
    WPF笔记(一)之初识XMAL
    创建理想的数据库索引
    常见负载均衡算法
    Java设计模式之外观模式
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12000193.html
Copyright © 2020-2023  润新知