HDU - 3555 - Bomb(数位DP)

Posted ydddd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 3555 - Bomb(数位DP)相关的知识,希望对你有一定的参考价值。

链接:

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;
}

以上是关于HDU - 3555 - Bomb(数位DP)的主要内容,如果未能解决你的问题,请参考以下文章

HDU 3555Bomb 数位DP

Bomb HDU - 3555 (数位DP)

HDU - 3555 - Bomb(数位DP)

HDU 3555 Bomb (数位DP)

HDU 3555 Bomb (数位dp)

[HDU3555] Bomb 数位DP