• hdu 3555 Bomb(数位dp入门)


    Bomb

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
    Total Submission(s): 24148    Accepted Submission(s): 9092

    Problem Description

    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?

    Input

    The first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description.
    The input terminates by end of file marker.

    Output

    For each test case, output an integer indicating the final points of the power.

    Sample Input

    3 1 50 500

    Sample Output

    0 1 15

    
    #include<bits/stdc++.h>
    #include<stdio.h>
    #include<iostream>
    #include<cmath>
    #include<math.h>
    #include<queue>
    #include<set>
    #include<map>
    #include<iomanip>
    #include<algorithm>
    #include<stack>
    using namespace std;
    #define inf 0x3f3f3f3f
    typedef long long ll;
    int bit[40];
    ll f[40][3];
    ll dp(int pos,int st,bool flag)
    {
        if(pos==0)return st==2;
        if(flag&&f[pos][st]!=-1)return f[pos][st];
        ll ans=0;
        int x=flag?9:bit[pos];
        for(int i=0;i<=x;i++)
        {
            if((st==2)||(st==1&&i==9))
            {
                ans+=dp(pos-1,2,flag||i<x);
            }
            else if(i==4)ans+=dp(pos-1,1,flag||i<x);
            else ans+=dp(pos-1,0,flag||i<x);
        }
        if(flag)f[pos][st]=ans;
        return ans;
    }
    ll calc(ll x)
    {
        int len=0;
        while(x)
        {
            bit[++len]=x%10;
            x/=10;
        }
        return dp(len,0,0);
    }
    
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
        int t;
        scanf("%d",&t);
        while(t--)
        {
            memset(f,-1,sizeof(f));
            ll n;
            scanf("%lld",&n);
            printf("%lld
    ",calc(n));
        }
        return 0;
    }
    
    
    
    
  • 相关阅读:
    Windows Server 2012 R2的安装(GUI桌面版本)
    CentOS安装-(CentOS7)最小化安装
    【转】Makefile步步为营
    【转载】人工智能必备数学知识
    【萌新向】cartographer_ros最新安装指南 2019-12
    Ubuntu 16.04 允许进行vnc远程控制【转】
    UVW平台运动控制算法以及matlab仿真
    Java语言基础13—IO
    Java数组元素去重(不使用集合)
    java基础12—集合类
  • 原文地址:https://www.cnblogs.com/linruier/p/9919160.html
Copyright © 2020-2023  润新知