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

HDU 3555 Bomb

时间:2016-01-28 00:28:18      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

数位DP

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <string>
using namespace std;

long long dp[25][25];
int p[25];
int tot;
long long a;

long long f(long long x)
{
    tot=0;
    while(x)
    {
        p[tot++]=(int)(x%10);
        x=x/10;
    }
    for(int i=0; i<tot/2; i++) swap(p[i],p[tot-i-1]);

    long long res=0;

    for(int i=0;i<tot;i++)
    {
        for(int j=0;j<p[i];j++)
        {
            if(p[i-1]==4&&j==9&&i>=1) continue;
            res=res+dp[tot-i][j];
        }
        if(p[i-1]==4&&p[i]==9&&i-1>=0) break;
    }

    return res;
}

void init()
{
    memset(dp,0,sizeof dp);
    for(int i=0;i<=9;i++) dp[1][i]=1;
    for(int i=2;i<=20;i++)
    {
        for(int j=0;j<=9;j++)
        {
            long long sum=0;
            for(int k=0;k<=9;k++)
            {
                if(j==4&&k==9) continue;
                else sum=sum+dp[i-1][k];
            }
            dp[i][j]=sum;
        }
    }
}

int main()
{
    init();
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%lld",&a);
        a++;
        printf("%lld\n",a-f(a));
    }
    return 0;
}

 

HDU 3555 Bomb

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/5164859.html

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