zoukankan      html  css  js  c++  java
  • HDU

    链接:

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

    题意:

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
    Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?

    思路:

    考虑没有49的数,用a-掉就行。
    Dp(i, j)
    i位置为j时的值。
    因为计算了0要多加1.

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MOD = 1e9+7;
    const int MAXN = 1e6+10;
    
    LL Dp[25][10];
    int dig[25];
    LL a;
    
    LL Dfs(int pos, int pre, int zer, int lim)
    {
        if (pos == -1)
            return 1;
        if (!lim && Dp[pos][pre] != -1)
            return Dp[pos][pre];
        int up = lim ? dig[pos] : 9;
        LL cnt = 0;
        for (int i = 0;i <= up;i++)
        {
            if (pre == 4 && i == 9)
                continue;
            cnt += Dfs(pos-1, i, zer && i == 0, lim && i == up);
        }
        if (!lim)
            Dp[pos][pre] = cnt;
        return cnt;
    }
    
    LL Solve(LL x)
    {
        int p = 0;
        while(x)
        {
            dig[p++] = x%10;
            x /= 10;
        }
        return Dfs(p-1, -1, 1, 1);
    }
    
    int main()
    {
        // freopen("test.in", "r", stdin);
        int t;
        scanf("%d", &t);
        memset(Dp, -1, sizeof(Dp));
        while(t--)
        {
            scanf("%lld", &a);
            printf("%lld
    ", a-Solve(a)+1);
        }
    
        return 0;
    }
    
  • 相关阅读:
    [08] 包装器类
    [07] String字符串
    [06] Java的数据类型
    [05] 利用private来封装
    [04] 包和访问权限修饰符
    [03] 类的结构和创建对象
    [02] 类和对象
    [01] Java语言的基本认识
    通过Excel认识POI
    浅谈SQL优化入门:3、利用索引
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11992803.html
Copyright © 2011-2022 走看看