码迷,mamicode.com
首页 > 其他好文 > 详细

HDU - 3555 - Bomb(数位DP)

时间:2019-12-06 00:03:07      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:clu   sizeof   max   hdu   pre   ace   include   power   tps   

链接:

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\n", a-Solve(a)+1);
    }

    return 0;
}

HDU - 3555 - Bomb(数位DP)

标签:clu   sizeof   max   hdu   pre   ace   include   power   tps   

原文地址:https://www.cnblogs.com/YDDDD/p/11992803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!